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
18 from sdnvpn.lib import config as sdnvpn_config
20 logger = ft_logger.Logger("sdnvpn-tempest").getLogger()
22 COMMON_CONFIG = sdnvpn_config.CommonConfig()
24 SUCCESS_CRITERIA = ft_utils.get_parameter_from_yaml(
25 "testcases.testcase_1.succes_criteria", COMMON_CONFIG.config_file)
29 src_tempest_dir = ft_utils.get_deployment_dir()
30 if not src_tempest_dir:
31 logger.error("Rally deployment not found.")
34 src_tempest_conf = src_tempest_dir + '/tempest.conf'
35 bgpvpn_tempest_conf = src_tempest_dir + '/bgpvpn_tempest.conf'
37 if not os.path.isfile(src_tempest_conf):
38 logger.error("tempest.conf not found in %s." % src_tempest_conf)
40 shutil.copy(src_tempest_conf, bgpvpn_tempest_conf)
42 logger.info("Copying tempest.conf to %s." % bgpvpn_tempest_conf)
43 config = ConfigParser.RawConfigParser()
44 config.read(bgpvpn_tempest_conf)
45 config.set('service_available', 'bgpvpn', 'True')
46 logger.debug("Updating %s with bgpvpn=True" % bgpvpn_tempest_conf)
47 with open(bgpvpn_tempest_conf, 'wb') as tempest_conf:
48 config.write(tempest_conf)
50 cmd_line = (src_tempest_dir +
51 "/run_tempest.sh -C %s -t -N -- "
52 "networking_bgpvpn_tempest" % bgpvpn_tempest_conf)
53 logger.info("Executing: %s" % cmd_line)
54 cmd = os.popen(cmd_line)
64 for match in re.findall('(.*?)[. ]*FAILED', output):
67 m = re.search('tests in(.*)sec', output)
69 # Look for num tests run
70 m = re.search('Ran:(.*)tests', output)
71 num_tests = m.group(1)
72 # Look for tests failed
73 m = re.search('Failed:(.*)', output)
75 # Look for name of the tests
76 testcases = re.findall("\{0\} (.*)", output)
78 results = {"duration": duration,
79 "num_tests": num_tests, "failed": failed,
82 if 100 - (100 * int(failed) / int(num_tests)) < int(SUCCESS_CRITERIA):
84 return {"status": status, "details": results}
86 logger.error("Problem when parsing the results.")
89 if __name__ == '__main__':