2017-06-20 21:01:11 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
Continuous integration toolkit. The purpose of this script is to generate
|
|
|
|
everything which is needed for the CI environment.
|
|
|
|
|
|
|
|
List of responsibilities:
|
2017-07-21 19:09:22 +08:00
|
|
|
* execute default suites
|
2017-06-20 21:01:11 +08:00
|
|
|
* terminate execution if any of internal scenarios fails
|
2017-08-24 21:03:21 +08:00
|
|
|
* creates the report file that is needed by the Apollo plugin
|
2017-06-20 21:01:11 +08:00
|
|
|
to post the status on Phabricator. (.quality_assurance_status)
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import json
|
|
|
|
import logging
|
2017-07-21 19:09:22 +08:00
|
|
|
import subprocess
|
2017-06-20 21:01:11 +08:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
# constants
|
|
|
|
memgraph_suite = "memgraph_V1"
|
2018-02-14 21:53:41 +08:00
|
|
|
extra_suites = ["openCypher_M09"]
|
2017-06-20 21:01:11 +08:00
|
|
|
results_folder = os.path.join("tck_engine", "results")
|
2017-07-21 19:09:22 +08:00
|
|
|
suite_suffix = "memgraph-{}.json"
|
2017-06-20 21:01:11 +08:00
|
|
|
qa_status_path = ".quality_assurance_status"
|
2017-12-28 23:27:30 +08:00
|
|
|
measurements_path = ".apollo_measurements"
|
2017-06-20 21:01:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
def get_newest_path(folder, suffix):
|
|
|
|
"""
|
|
|
|
:param folder: Scanned folder.
|
|
|
|
:param suffix: File suffix.
|
|
|
|
|
|
|
|
:return: Path to the newest file in the folder with the specified suffix.
|
|
|
|
"""
|
|
|
|
name_list = sorted(filter(lambda x: x.endswith(suffix),
|
|
|
|
os.listdir(folder)))
|
|
|
|
if len(name_list) <= 0:
|
|
|
|
sys.exit("Unable to find any file with suffix %s in folder %s!" %
|
|
|
|
(suffix, folder))
|
|
|
|
return os.path.join(folder, name_list.pop())
|
|
|
|
|
|
|
|
|
2017-12-28 23:27:30 +08:00
|
|
|
def generate_measurements(suite, result_path):
|
2017-06-20 21:01:11 +08:00
|
|
|
"""
|
|
|
|
:param suite: Test suite name.
|
2017-12-28 23:27:30 +08:00
|
|
|
:param result_path: File path with json status report.
|
|
|
|
|
|
|
|
:return: Measurements string.
|
|
|
|
"""
|
|
|
|
with open(result_path) as f:
|
|
|
|
result = json.load(f)
|
|
|
|
ret = ""
|
|
|
|
for i in ["total", "passed"]:
|
|
|
|
ret += "{}.{} {}\n".format(suite, i, result[i])
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
def generate_status(suite, result_path, required = False):
|
|
|
|
"""
|
|
|
|
:param suite: Test suite name.
|
|
|
|
:param result_path: File path with json status report.
|
2017-08-24 21:03:21 +08:00
|
|
|
:param required: Adds status ticks to the message if required.
|
2017-06-20 21:01:11 +08:00
|
|
|
|
|
|
|
:return: Status string.
|
|
|
|
"""
|
2017-12-28 23:27:30 +08:00
|
|
|
with open(result_path) as f:
|
|
|
|
result = json.load(f)
|
2017-06-20 21:01:11 +08:00
|
|
|
total = result["total"]
|
|
|
|
passed = result["passed"]
|
2017-08-24 21:03:21 +08:00
|
|
|
ratio = passed / total
|
|
|
|
msg = "{} / {} //({:.2%})//".format(passed, total, ratio)
|
|
|
|
if required:
|
|
|
|
if passed == total:
|
|
|
|
msg += " {icon check color=green}"
|
|
|
|
else:
|
|
|
|
msg += " {icon times color=red}"
|
|
|
|
return (msg, passed, total)
|
|
|
|
|
|
|
|
|
|
|
|
def generate_remarkup(data):
|
|
|
|
"""
|
|
|
|
:param data: Tabular data to convert to remarkup.
|
|
|
|
|
|
|
|
:return: Remarkup formatted status string.
|
|
|
|
"""
|
|
|
|
ret = "==== Quality assurance status: ====\n\n"
|
|
|
|
ret += "<table>\n"
|
|
|
|
for row in data:
|
|
|
|
ret += " <tr>\n"
|
|
|
|
for item in row:
|
|
|
|
if row == data[0]:
|
|
|
|
fmt = " <th>{}</th>\n"
|
|
|
|
else:
|
|
|
|
fmt = " <td>{}</td>\n"
|
|
|
|
ret += fmt.format(item)
|
|
|
|
ret += " </tr>\n"
|
|
|
|
ret += "</table>\n"
|
|
|
|
return ret
|
2017-06-20 21:01:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# logger config
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
2017-07-21 19:09:22 +08:00
|
|
|
# run suites
|
|
|
|
log.info("Starting Memgraph scenarios.")
|
|
|
|
subprocess.run(["./run", "--test-suite", memgraph_suite], check = True)
|
|
|
|
for suite in extra_suites:
|
|
|
|
log.info("Starting extra suite '{}' scenarios.".format(suite))
|
|
|
|
subprocess.run(["./run", "--test-suite", suite])
|
|
|
|
|
2017-06-20 21:01:11 +08:00
|
|
|
# get data files (memgraph internal test + openCypher TCK test results)
|
2017-07-21 19:09:22 +08:00
|
|
|
memgraph_result_path = get_newest_path(results_folder,
|
|
|
|
suite_suffix.format(memgraph_suite))
|
|
|
|
log.info("Memgraph result path is {}".format(memgraph_result_path))
|
2017-06-20 21:01:11 +08:00
|
|
|
|
2017-12-28 23:27:30 +08:00
|
|
|
# measurements
|
|
|
|
measurements = ""
|
|
|
|
|
2017-08-24 21:03:21 +08:00
|
|
|
# status table headers
|
|
|
|
status_data = [["Suite", "Scenarios"]]
|
|
|
|
|
2017-06-20 21:01:11 +08:00
|
|
|
# read internal scenarios
|
2017-12-28 23:27:30 +08:00
|
|
|
memgraph_status, memgraph_passed, memgraph_total = generate_status(
|
|
|
|
memgraph_suite, memgraph_result_path, required = True)
|
2017-08-24 21:03:21 +08:00
|
|
|
status_data.append([memgraph_suite, memgraph_status])
|
2017-12-28 23:27:30 +08:00
|
|
|
measurements += generate_measurements(memgraph_suite, memgraph_result_path)
|
2017-07-21 19:09:22 +08:00
|
|
|
|
|
|
|
# read extra scenarios
|
|
|
|
for suite in extra_suites:
|
|
|
|
result_path = get_newest_path(results_folder, suite_suffix.format(suite))
|
|
|
|
log.info("Extra suite '{}' result path is {}".format(suite, result_path))
|
2017-12-28 23:27:30 +08:00
|
|
|
suite_status, _, _ = generate_status(suite, result_path)
|
2017-08-24 21:03:21 +08:00
|
|
|
status_data.append([suite, suite_status])
|
2017-12-28 23:27:30 +08:00
|
|
|
measurements += generate_measurements(suite, result_path)
|
2017-08-24 21:03:21 +08:00
|
|
|
|
|
|
|
# create status message
|
|
|
|
qa_status_message = generate_remarkup(status_data)
|
2017-06-20 21:01:11 +08:00
|
|
|
|
|
|
|
# create the report file
|
|
|
|
with open(qa_status_path, "w") as f:
|
2017-07-21 19:09:22 +08:00
|
|
|
f.write(qa_status_message)
|
2017-06-20 21:01:11 +08:00
|
|
|
|
2017-12-28 23:27:30 +08:00
|
|
|
# create the measurements file
|
|
|
|
with open(measurements_path, "w") as f:
|
|
|
|
f.write(measurements)
|
|
|
|
|
2017-06-20 21:01:11 +08:00
|
|
|
log.info("Status is generated in %s" % qa_status_path)
|
2017-12-28 23:27:30 +08:00
|
|
|
log.info("Measurements are generated in %s" % measurements_path)
|
2017-06-20 21:01:11 +08:00
|
|
|
|
|
|
|
if memgraph_total != memgraph_passed:
|
|
|
|
sys.exit("There is a problem with internal scenarios! %s"
|
|
|
|
% memgraph_status)
|