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
16 import functest.utils.functest_logger as ft_logger
17 import functest.utils.functest_utils as ft_utils
19 logger = ft_logger.Logger("sdnvpn-tempest").getLogger()
23 src_tempest_dir = ft_utils.get_deployment_dir()
24 if not src_tempest_dir:
25 logger.error("Rally deployment not found.")
28 src_tempest_conf = src_tempest_dir + '/tempest.conf'
29 bgpvpn_tempest_conf = src_tempest_dir + '/bgpvpn_tempest.conf'
31 if not os.path.isfile(src_tempest_conf):
32 logger.error("tempest.conf not found in %s." % src_tempest_conf)
34 shutil.copy(src_tempest_conf, bgpvpn_tempest_conf)
36 logger.info("Copying tempest.conf to %s." % bgpvpn_tempest_conf)
37 config = ConfigParser.RawConfigParser()
38 config.read(bgpvpn_tempest_conf)
39 config.set('service_available', 'bgpvpn', 'True')
40 logger.debug("Updating %s with bgpvpn=True" % bgpvpn_tempest_conf)
41 with open(bgpvpn_tempest_conf, 'wb') as tempest_conf:
42 config.write(tempest_conf)
44 cmd_line = (src_tempest_dir +
45 "/run_tempest.sh -C %s -t -N -- "
46 "networking_bgpvpn_tempest" % bgpvpn_tempest_conf)
47 logger.info("Executing: %s" % cmd_line)
48 cmd = os.popen(cmd_line)
58 for match in re.findall('(.*?)[. ]*FAILED', output):
61 m = re.search('tests in(.*)sec', output)
63 # Look for num tests run
64 m = re.search('Ran:(.*)tests', output)
65 num_tests = m.group(1)
66 # Look for tests failed
67 m = re.search('Failed:(.*)', output)
69 # Look for name of the tests
70 testcases = re.findall("\{0\} (.*)", output)
72 results = {"duration": duration,
73 "num_tests": num_tests, "failed": failed,
80 return {"status": status, "details": results}
82 logger.error("Problem when parsing the results.")
85 if __name__ == '__main__':