2022-10-17 14:46:50 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
import sys
|
2023-01-03 14:23:19 +00:00
|
|
|
from typing import List
|
2022-10-17 14:46:50 +00:00
|
|
|
|
|
|
|
from github import Github
|
|
|
|
|
2023-01-03 14:23:19 +00:00
|
|
|
from build_download_helper import get_build_name_for_check, read_build_urls
|
|
|
|
from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse
|
2023-04-18 14:58:17 +00:00
|
|
|
from commit_status_helper import (
|
|
|
|
RerunHelper,
|
|
|
|
format_description,
|
|
|
|
get_commit,
|
|
|
|
post_commit_status,
|
|
|
|
)
|
2023-01-03 14:23:19 +00:00
|
|
|
from docker_pull_helper import get_image_with_version
|
2022-10-17 14:46:50 +00:00
|
|
|
from env_helper import (
|
|
|
|
GITHUB_RUN_URL,
|
|
|
|
REPORTS_PATH,
|
|
|
|
TEMP_PATH,
|
|
|
|
)
|
|
|
|
from get_robot_token import get_best_robot_token
|
|
|
|
from pr_info import PRInfo
|
2023-01-03 14:23:19 +00:00
|
|
|
from report import TestResults, TestResult
|
|
|
|
from s3_helper import S3Helper
|
|
|
|
from stopwatch import Stopwatch
|
|
|
|
from upload_result_helper import upload_results
|
2022-10-17 14:46:50 +00:00
|
|
|
|
|
|
|
IMAGE_NAME = "clickhouse/sqlancer-test"
|
|
|
|
|
|
|
|
|
2023-01-10 15:40:31 +00:00
|
|
|
def get_pull_command(docker_image):
|
2023-01-10 22:17:28 +00:00
|
|
|
return f"docker pull {docker_image}"
|
2023-01-10 16:17:59 +00:00
|
|
|
|
2023-01-10 15:40:31 +00:00
|
|
|
|
2022-10-17 14:46:50 +00:00
|
|
|
def get_run_command(download_url, workspace_path, image):
|
|
|
|
return (
|
|
|
|
f"docker run "
|
|
|
|
# For sysctl
|
|
|
|
"--privileged "
|
|
|
|
"--network=host "
|
|
|
|
f"--volume={workspace_path}:/workspace "
|
|
|
|
"--cap-add syslog --cap-add sys_admin --cap-add=SYS_PTRACE "
|
|
|
|
f'-e BINARY_URL_TO_DOWNLOAD="{download_url}" '
|
|
|
|
f"{image}"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-01-03 14:23:19 +00:00
|
|
|
def main():
|
2022-10-17 14:46:50 +00:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
|
stopwatch = Stopwatch()
|
|
|
|
|
|
|
|
temp_path = TEMP_PATH
|
|
|
|
reports_path = REPORTS_PATH
|
|
|
|
|
|
|
|
check_name = sys.argv[1]
|
|
|
|
|
|
|
|
if not os.path.exists(temp_path):
|
|
|
|
os.makedirs(temp_path)
|
|
|
|
|
|
|
|
pr_info = PRInfo()
|
|
|
|
|
|
|
|
gh = Github(get_best_robot_token(), per_page=100)
|
2023-04-18 14:58:17 +00:00
|
|
|
commit = get_commit(gh, pr_info.sha)
|
2022-10-17 14:46:50 +00:00
|
|
|
|
2023-04-18 14:58:17 +00:00
|
|
|
rerun_helper = RerunHelper(commit, check_name)
|
2022-10-17 14:46:50 +00:00
|
|
|
if rerun_helper.is_already_finished_by_status():
|
|
|
|
logging.info("Check is already finished according to github status, exiting")
|
|
|
|
sys.exit(0)
|
|
|
|
|
2022-10-18 15:14:42 +00:00
|
|
|
docker_image = get_image_with_version(reports_path, IMAGE_NAME)
|
2022-10-17 14:46:50 +00:00
|
|
|
|
|
|
|
build_name = get_build_name_for_check(check_name)
|
|
|
|
print(build_name)
|
|
|
|
urls = read_build_urls(build_name, reports_path)
|
|
|
|
if not urls:
|
|
|
|
raise Exception("No build URLs found")
|
|
|
|
|
|
|
|
for url in urls:
|
|
|
|
if url.endswith("/clickhouse"):
|
|
|
|
build_url = url
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise Exception("Cannot find binary clickhouse among build results")
|
|
|
|
|
|
|
|
logging.info("Got build url %s", build_url)
|
|
|
|
|
|
|
|
workspace_path = os.path.join(temp_path, "workspace")
|
|
|
|
if not os.path.exists(workspace_path):
|
|
|
|
os.makedirs(workspace_path)
|
|
|
|
|
2023-01-10 15:40:31 +00:00
|
|
|
pull_command = get_pull_command(docker_image)
|
|
|
|
|
|
|
|
logging.info("Going to pull image %s", pull_command)
|
|
|
|
|
|
|
|
pull_log_path = os.path.join(workspace_path, "pull.log")
|
|
|
|
with open(pull_log_path, "w", encoding="utf-8") as log:
|
|
|
|
with subprocess.Popen(
|
|
|
|
pull_command, shell=True, stderr=log, stdout=log
|
|
|
|
) as process:
|
|
|
|
retcode = process.wait()
|
|
|
|
if retcode == 0:
|
|
|
|
logging.info("Pull successfully")
|
|
|
|
else:
|
|
|
|
logging.info("Pull failed")
|
|
|
|
|
2022-10-17 14:46:50 +00:00
|
|
|
run_command = get_run_command(build_url, workspace_path, docker_image)
|
|
|
|
logging.info("Going to run %s", run_command)
|
|
|
|
|
2022-12-26 15:29:32 +00:00
|
|
|
run_log_path = os.path.join(workspace_path, "run.log")
|
2022-10-17 14:46:50 +00:00
|
|
|
with open(run_log_path, "w", encoding="utf-8") as log:
|
|
|
|
with subprocess.Popen(
|
|
|
|
run_command, shell=True, stderr=log, stdout=log
|
|
|
|
) as process:
|
|
|
|
retcode = process.wait()
|
|
|
|
if retcode == 0:
|
|
|
|
logging.info("Run successfully")
|
|
|
|
else:
|
|
|
|
logging.info("Run failed")
|
|
|
|
|
|
|
|
subprocess.check_call(f"sudo chown -R ubuntu:ubuntu {temp_path}", shell=True)
|
|
|
|
|
2022-10-25 10:34:55 +00:00
|
|
|
tests = [
|
|
|
|
"TLPGroupBy",
|
|
|
|
"TLPHaving",
|
|
|
|
"TLPWhere",
|
2022-10-28 09:47:16 +00:00
|
|
|
"TLPDistinct",
|
|
|
|
"TLPAggregate",
|
2022-10-25 10:34:55 +00:00
|
|
|
"NoREC",
|
|
|
|
]
|
|
|
|
|
2022-10-26 08:30:20 +00:00
|
|
|
paths = [
|
|
|
|
run_log_path,
|
2023-01-10 15:40:31 +00:00
|
|
|
pull_log_path,
|
2022-10-26 15:06:01 +00:00
|
|
|
os.path.join(workspace_path, "clickhouse-server.log"),
|
2022-10-26 08:30:20 +00:00
|
|
|
os.path.join(workspace_path, "stderr.log"),
|
|
|
|
os.path.join(workspace_path, "stdout.log"),
|
|
|
|
]
|
2022-10-25 10:34:55 +00:00
|
|
|
for t in tests:
|
|
|
|
err_name = f"{t}.err"
|
2022-10-27 09:06:11 +00:00
|
|
|
log_name = f"{t}.out"
|
2022-10-26 08:30:20 +00:00
|
|
|
paths.append(os.path.join(workspace_path, err_name))
|
|
|
|
paths.append(os.path.join(workspace_path, log_name))
|
2022-10-17 14:46:50 +00:00
|
|
|
|
|
|
|
s3_helper = S3Helper()
|
|
|
|
report_url = GITHUB_RUN_URL
|
|
|
|
|
2022-10-28 11:28:20 +00:00
|
|
|
status = "success"
|
2023-01-03 14:23:19 +00:00
|
|
|
test_results = [] # type: TestResults
|
2022-10-18 15:14:42 +00:00
|
|
|
# Try to get status message saved by the SQLancer
|
|
|
|
try:
|
2023-06-23 16:55:04 +00:00
|
|
|
with open(
|
|
|
|
os.path.join(workspace_path, "status.txt"), "r", encoding="utf-8"
|
|
|
|
) as status_f:
|
|
|
|
status = status_f.readline().rstrip("\n")
|
2022-10-27 17:56:08 +00:00
|
|
|
if os.path.exists(os.path.join(workspace_path, "server_crashed.log")):
|
2023-01-03 14:23:19 +00:00
|
|
|
test_results.append(TestResult("Server crashed", "FAIL"))
|
2022-10-19 17:02:49 +00:00
|
|
|
with open(
|
|
|
|
os.path.join(workspace_path, "summary.tsv"), "r", encoding="utf-8"
|
|
|
|
) as summary_f:
|
|
|
|
for line in summary_f:
|
2022-11-10 11:05:35 +00:00
|
|
|
l = line.rstrip("\n").split("\t")
|
2023-01-03 14:23:19 +00:00
|
|
|
test_results.append(TestResult(l[0], l[1]))
|
2022-10-19 17:02:49 +00:00
|
|
|
|
2022-10-18 15:14:42 +00:00
|
|
|
with open(
|
|
|
|
os.path.join(workspace_path, "description.txt"), "r", encoding="utf-8"
|
|
|
|
) as desc_f:
|
2023-02-23 14:21:19 +00:00
|
|
|
description = desc_f.readline().rstrip("\n")
|
2022-10-18 15:14:42 +00:00
|
|
|
except:
|
2023-06-23 16:55:04 +00:00
|
|
|
status = "failure"
|
2022-10-18 15:14:42 +00:00
|
|
|
description = "Task failed: $?=" + str(retcode)
|
|
|
|
|
2023-02-27 12:11:17 +00:00
|
|
|
description = format_description(description)
|
2023-02-23 14:21:19 +00:00
|
|
|
|
2022-10-21 11:48:58 +00:00
|
|
|
report_url = upload_results(
|
|
|
|
s3_helper,
|
|
|
|
pr_info.number,
|
|
|
|
pr_info.sha,
|
|
|
|
test_results,
|
|
|
|
paths,
|
|
|
|
check_name,
|
|
|
|
)
|
|
|
|
|
2023-04-18 23:03:48 +00:00
|
|
|
post_commit_status(commit, status, report_url, description, check_name, pr_info)
|
2022-10-21 11:48:58 +00:00
|
|
|
print(f"::notice:: {check_name} Report url: {report_url}")
|
|
|
|
|
2022-10-17 14:46:50 +00:00
|
|
|
ch_helper = ClickHouseHelper()
|
|
|
|
prepared_events = prepare_tests_results_for_clickhouse(
|
|
|
|
pr_info,
|
2022-10-21 19:43:06 +00:00
|
|
|
test_results,
|
2022-10-17 14:46:50 +00:00
|
|
|
status,
|
|
|
|
stopwatch.duration_seconds,
|
|
|
|
stopwatch.start_time_str,
|
|
|
|
report_url,
|
|
|
|
check_name,
|
|
|
|
)
|
|
|
|
ch_helper.insert_events_into(db="default", table="checks", events=prepared_events)
|
|
|
|
|
2023-01-03 14:23:19 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|