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("-d", "--debug", help="Debug mode", action="store_true")
28 parser.add_argument("-m", "--mode", help="Tempest test mode [smoke, all]",
30 parser.add_argument("-r", "--report",
31 help="Create json result file",
34 args = parser.parse_args()
36 """ logging configuration """
37 logger = logging.getLogger('run_tempest')
38 logger.setLevel(logging.DEBUG)
40 ch = logging.StreamHandler()
42 ch.setLevel(logging.DEBUG)
44 ch.setLevel(logging.INFO)
46 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
47 ch.setFormatter(formatter)
50 REPO_PATH=os.environ['repos_dir']+'/functest/'
51 if not os.path.exists(REPO_PATH):
52 logger.error("Functest repository directory not found '%s'" % REPO_PATH)
54 sys.path.append(REPO_PATH + "testcases/")
57 with open(REPO_PATH+"testcases/config_functest.yaml") as f:
58 functest_yaml = yaml.safe_load(f)
60 TEST_DB = functest_yaml.get("results").get("test_db_url")
65 def get_info(file_result):
70 p = subprocess.Popen('cat tempest.log',
71 shell=True, stdout=subprocess.PIPE,
72 stderr=subprocess.STDOUT)
73 for line in p.stdout.readlines():
75 if (len(test_run) < 1):
76 test_run = re.findall("[0-9]*\.[0-9]*s", line)
77 if (len(duration) < 1):
78 duration = re.findall("[0-9]*\ tests", line)
79 regexp = r"(failures=[0-9]+)"
80 if (len(test_failed) < 1):
81 test_failed = re.findall(regexp, line)
85 logger.debug("test_run:"+test_run)
86 logger.debug("duration:"+duration)
89 def push_results_to_db(payload, module, pod_name):
91 # TODO move DB creds into config file
92 url = TEST_DB + "/results"
93 installer = functest_utils.get_installer_type(logger)
94 git_version = functest_utils.get_git_branch(REPO_PATH)
95 logger.info("Pushing results to DB: '%s'." % url)
97 params = {"project_name": "functest", "case_name": "Tempest",
98 "pod_name": str(pod_name), 'installer': installer,
99 "version": git_version, 'details': payload}
100 headers = {'Content-Type': 'application/json'}
102 r = requests.post(url, data=json.dumps(params), headers=headers)
106 def run_tempest(OPTION):
108 # the "main" function of the script which launches Rally to run Tempest
109 # :param option: tempest option (smoke, ..)
112 logger.info("Starting Tempest test suite: '%s'." % OPTION)
113 cmd_line = "rally verify start "+OPTION
114 logger.debug('Executing command : {}'.format(cmd_line))
115 subprocess.call(cmd_line, shell=True, stderr=subprocess.STDOUT)
117 cmd_line = "rally verify list"
118 logger.debug('Executing command : {}'.format(cmd_line))
119 cmd = os.popen(cmd_line)
120 output = (((cmd.read()).splitlines()[3]).replace(" ", "")).split("|")
122 # | UUID | Deployment UUID | smoke | tests | failures | Created at |
123 # Duration | Status |
124 num_tests = output[4]
125 num_failures = output[5]
126 time_start = output[6]
128 # Compute duration (lets assume it does not take more than 60 min)
129 dur_min=int(duration.split(':')[1])
130 dur_sec_float=float(duration.split(':')[2])
131 dur_sec_int=int(round(dur_sec_float,0))
132 dur_sec_int = dur_sec_int + 60 * dur_min
134 # Generate json results for DB
135 json_results = {"timestart": time_start, "duration": dur_sec_int,
136 "tests": int(num_tests), "failures": int(num_failures)}
137 logger.info("Results: "+str(json_results))
138 pod_name = functest_utils.get_pod_name(logger)
140 # Push results in payload of testcase
142 logger.debug("Push result into DB")
143 push_results_to_db(json_results, MODE, pod_name)
150 elif not (args.mode in modes):
151 logger.error("Tempest mode not valid. Possible values are:\n"
160 if __name__ == '__main__':