4 # Runs tempest and pushes the results to the DB
7 # morgan.richomme@orange.com
8 # jose.lausuch@ericsson.com
21 modes = ['full', 'smoke', 'baremetal', 'compute', 'data_processing',
22 'identity', 'image', 'network', 'object_storage', 'orchestration',
23 'telemetry', 'volume']
25 """ tests configuration """
26 parser = argparse.ArgumentParser()
27 parser.add_argument("repo_path", help="Path to the Functest repository")
28 parser.add_argument("-d", "--debug", help="Debug mode", action="store_true")
29 parser.add_argument("-m", "--mode", help="Tempest test mode [smoke, all]",
32 args = parser.parse_args()
34 """ logging configuration """
35 logger = logging.getLogger('run_tempest')
36 logger.setLevel(logging.DEBUG)
38 ch = logging.StreamHandler()
40 ch.setLevel(logging.DEBUG)
42 ch.setLevel(logging.INFO)
44 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
45 ch.setFormatter(formatter)
48 with open(args.repo_path+"/testcases/config_functest.yaml") as f:
49 functest_yaml = yaml.safe_load(f)
52 REPO_PATH = args.repo_path
53 TEST_DB = functest_yaml.get("results").get("test_db_url")
54 sys.path.append(args.repo_path + "/testcases/")
60 def get_info(file_result):
65 p = subprocess.Popen('cat tempest.log',
66 shell=True, stdout=subprocess.PIPE,
67 stderr=subprocess.STDOUT)
68 for line in p.stdout.readlines():
70 if (len(test_run) < 1):
71 test_run = re.findall("[0-9]*\.[0-9]*s", line)
72 if (len(duration) < 1):
73 duration = re.findall("[0-9]*\ tests", line)
74 regexp = r"(failures=[0-9]+)"
75 if (len(test_failed) < 1):
76 test_failed = re.findall(regexp, line)
80 logger.debug("test_run:"+test_run)
81 logger.debug("duration:"+duration)
84 def push_results_to_db(payload, module, pod_name):
86 # TODO move DB creds into config file
87 url = TEST_DB + "/results"
88 installer = functest_utils.get_installer_type(logger)
89 git_version = functest_utils.get_git_branch(REPO_PATH)
90 logger.info("Pushing results to DB: '%s'." % url)
92 params = {"project_name": "functest", "case_name": "Tempest",
93 "pod_name": str(pod_name), 'installer': installer,
94 "version": git_version, 'details': payload}
95 headers = {'Content-Type': 'application/json'}
97 r = requests.post(url, data=json.dumps(params), headers=headers)
101 def run_tempest(OPTION):
103 # the "main" function of the script which launches Rally to run Tempest
104 # :param option: tempest option (smoke, ..)
107 logger.info("Starting Tempest test suite: '%s'." % OPTION)
108 cmd_line = "rally verify start "+OPTION
109 logger.debug('Executing command : {}'.format(cmd_line))
110 subprocess.call(cmd_line, shell=True, stderr=subprocess.STDOUT)
112 cmd_line = "rally verify list"
113 logger.debug('Executing command : {}'.format(cmd_line))
114 cmd = os.popen(cmd_line)
115 output = (((cmd.read()).splitlines()[3]).replace(" ", "")).split("|")
117 # | UUID | Deployment UUID | smoke | tests | failures | Created at |
118 # Duration | Status |
119 num_tests = output[4]
120 num_failures = output[5]
121 time_start = output[6]
123 # Compute duration (lets assume it does not take more than 60 min)
124 dur_min=int(duration.split(':')[1])
125 dur_sec_float=float(duration.split(':')[2])
126 dur_sec_int=int(round(dur_sec_float,0))
127 dur_sec_int = dur_sec_int + 60 * dur_min
129 # Generate json results for DB
130 json_results = {"timestart": time_start, "duration": dur_sec_int,
131 "tests": int(num_tests), "failures": int(num_failures)}
132 logger.info("Results: "+str(json_results))
133 pod_name = functest_utils.get_pod_name(logger)
134 push_results_to_db(json_results, MODE, pod_name)
141 elif not (args.mode in modes):
142 logger.error("Tempest mode not valid. Possible values are:\n"
151 if __name__ == '__main__':