3 # Copyright (c) 2017 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
17 import functest.opnfv_tests.openstack.tempest.conf_utils as tempest_utils
19 logger = logging.getLogger('sdnvpn-tempest')
23 verifier_id = tempest_utils.get_verifier_id()
24 verifier_repo_dir = tempest_utils.get_verifier_repo_dir(
26 deployment_id = tempest_utils.get_verifier_deployment_id()
27 src_tempest_dir = tempest_utils.get_verifier_deployment_dir(
28 verifier_id, deployment_id)
31 if not src_tempest_dir:
32 logger.error("Rally deployment not found.")
35 tempest_utils.configure_verifier(src_tempest_dir)
37 src_tempest_conf = os.path.join(src_tempest_dir, 'tempest.conf')
38 bgpvpn_tempest_conf = os.path.join(src_tempest_dir, 'bgpvpn_tempest.conf')
39 bgpvpn_tempest_list = os.path.join(src_tempest_dir, 'tempest_list.txt')
41 if not os.path.isfile(src_tempest_conf):
42 logger.error("tempest.conf not found in %s." % src_tempest_conf)
44 shutil.copy(src_tempest_conf, bgpvpn_tempest_conf)
46 logger.info("Copying tempest.conf to %s." % bgpvpn_tempest_conf)
47 config = ConfigParser.RawConfigParser()
48 config.read(bgpvpn_tempest_conf)
49 config.set('service_available', 'bgpvpn', 'True')
50 logger.debug("Updating %s with bgpvpn=True" % bgpvpn_tempest_conf)
51 with open(bgpvpn_tempest_conf, 'wb') as tempest_conf:
52 config.write(tempest_conf)
55 "testr list-tests networking_bgpvpn_tempest > {1};"
56 "cd -;".format(verifier_repo_dir, bgpvpn_tempest_list))
57 logger.info("Generating bgpvpn tempest list: %s" % cmd)
60 cmd_line = ("tempest run --config-file {0} -t --whitelist-file {1}"
61 .format(bgpvpn_tempest_conf, bgpvpn_tempest_list))
62 logger.info("Executing: %s" % cmd_line)
63 cmd = os.popen(cmd_line)
74 for match in re.findall('(.*?)[. ]*FAILED', output):
77 m = re.search('tests in(.*)sec', output)
79 # Look for num tests run
80 m = re.search('Ran:(.*)tests', output)
81 num_tests = m.group(1)
82 # Look for tests failed
83 m = re.search('Failed:(.*)', output)
85 # Look for name of the tests
86 testcases = re.findall("\{0\} (.*)", output)
88 results = {"duration": duration,
89 "num_tests": num_tests, "failed": failed,
96 return {"status": status, "details": results}
98 logger.error("Problem when parsing the results.")
101 if __name__ == '__main__':
102 logging.basicConfig(level=logging.INFO)