2021-11-02 13:38:55 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import logging
|
2023-12-18 08:07:22 +00:00
|
|
|
import os
|
2021-11-02 13:38:55 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2023-08-16 20:53:51 +00:00
|
|
|
from pathlib import Path
|
2021-11-02 13:38:55 +00:00
|
|
|
|
2023-01-03 14:23:19 +00:00
|
|
|
from build_download_helper import get_build_name_for_check, read_build_urls
|
2023-08-12 20:41:56 +00:00
|
|
|
from clickhouse_helper import (
|
2023-08-16 20:53:51 +00:00
|
|
|
CiLogsCredentials,
|
2023-04-18 14:58:17 +00:00
|
|
|
)
|
2023-12-18 08:07:22 +00:00
|
|
|
from docker_images_helper import DockerImage, get_docker_image, pull_image
|
|
|
|
from env_helper import REPORT_PATH, TEMP_PATH
|
2021-11-26 14:00:09 +00:00
|
|
|
from pr_info import PRInfo
|
2024-01-04 15:35:09 +00:00
|
|
|
from report import JobReport
|
2023-01-03 14:23:19 +00:00
|
|
|
from stopwatch import Stopwatch
|
2023-08-16 20:53:51 +00:00
|
|
|
from tee_popen import TeePopen
|
2021-11-02 13:38:55 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
IMAGE_NAME = "clickhouse/fuzzer"
|
|
|
|
|
2021-11-02 13:38:55 +00:00
|
|
|
|
2023-08-12 20:41:56 +00:00
|
|
|
def get_run_command(
|
2023-08-16 20:53:51 +00:00
|
|
|
pr_info: PRInfo,
|
|
|
|
build_url: str,
|
2023-09-27 14:27:37 +00:00
|
|
|
workspace_path: Path,
|
2023-08-16 20:53:51 +00:00
|
|
|
ci_logs_args: str,
|
|
|
|
image: DockerImage,
|
|
|
|
) -> str:
|
2023-08-12 20:41:56 +00:00
|
|
|
envs = [
|
2023-08-16 20:53:51 +00:00
|
|
|
f"-e PR_TO_TEST={pr_info.number}",
|
|
|
|
f"-e SHA_TO_TEST={pr_info.sha}",
|
|
|
|
f"-e BINARY_URL_TO_DOWNLOAD='{build_url}'",
|
2023-08-12 20:41:56 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
env_str = " ".join(envs)
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
return (
|
2022-08-29 18:36:13 +00:00
|
|
|
f"docker run "
|
|
|
|
# For sysctl
|
|
|
|
"--privileged "
|
|
|
|
"--network=host "
|
2023-08-16 20:53:51 +00:00
|
|
|
f"{ci_logs_args}"
|
2022-08-29 18:36:13 +00:00
|
|
|
f"--volume={workspace_path}:/workspace "
|
2023-08-12 20:41:56 +00:00
|
|
|
f"{env_str} "
|
2022-03-22 16:39:58 +00:00
|
|
|
"--cap-add syslog --cap-add sys_admin --cap-add=SYS_PTRACE "
|
|
|
|
f"{image}"
|
|
|
|
)
|
|
|
|
|
2021-11-02 13:38:55 +00:00
|
|
|
|
2023-04-06 10:46:43 +00:00
|
|
|
def main():
|
2021-11-02 13:38:55 +00:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
2021-11-19 14:47:04 +00:00
|
|
|
|
|
|
|
stopwatch = Stopwatch()
|
|
|
|
|
2023-09-27 14:27:37 +00:00
|
|
|
temp_path = Path(TEMP_PATH)
|
2023-12-18 08:07:22 +00:00
|
|
|
reports_path = Path(REPORT_PATH)
|
2023-09-27 14:27:37 +00:00
|
|
|
temp_path.mkdir(parents=True, exist_ok=True)
|
2021-11-02 13:38:55 +00:00
|
|
|
|
2023-12-18 08:07:22 +00:00
|
|
|
check_name = sys.argv[1] if len(sys.argv) > 1 else os.getenv("CHECK_NAME")
|
|
|
|
assert (
|
|
|
|
check_name
|
|
|
|
), "Check name must be provided as an input arg or in CHECK_NAME env"
|
2021-11-02 13:38:55 +00:00
|
|
|
|
2021-11-26 14:00:09 +00:00
|
|
|
pr_info = PRInfo()
|
2021-11-02 13:38:55 +00:00
|
|
|
|
2023-12-18 08:07:22 +00:00
|
|
|
docker_image = pull_image(get_docker_image(IMAGE_NAME))
|
2021-11-02 13:38:55 +00:00
|
|
|
|
2021-11-26 10:57:36 +00:00
|
|
|
build_name = get_build_name_for_check(check_name)
|
2022-09-07 13:06:44 +00:00
|
|
|
urls = read_build_urls(build_name, reports_path)
|
2021-11-02 13:38:55 +00:00
|
|
|
if not urls:
|
|
|
|
raise Exception("No build URLs found")
|
|
|
|
|
|
|
|
for url in urls:
|
2022-03-22 16:39:58 +00:00
|
|
|
if url.endswith("/clickhouse"):
|
2021-11-02 13:38:55 +00:00
|
|
|
build_url = url
|
|
|
|
break
|
|
|
|
else:
|
2023-07-19 01:42:32 +00:00
|
|
|
raise Exception("Cannot find the clickhouse binary among build results")
|
2021-11-02 13:38:55 +00:00
|
|
|
|
|
|
|
logging.info("Got build url %s", build_url)
|
|
|
|
|
2023-09-27 14:27:37 +00:00
|
|
|
workspace_path = temp_path / "workspace"
|
|
|
|
workspace_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
ci_logs_credentials = CiLogsCredentials(temp_path / "export-logs-config.sh")
|
2023-08-16 20:53:51 +00:00
|
|
|
ci_logs_args = ci_logs_credentials.get_docker_arguments(
|
|
|
|
pr_info, stopwatch.start_time_str, check_name
|
|
|
|
)
|
2021-11-02 13:38:55 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
run_command = get_run_command(
|
2023-08-16 20:53:51 +00:00
|
|
|
pr_info,
|
2023-08-12 20:41:56 +00:00
|
|
|
build_url,
|
|
|
|
workspace_path,
|
2023-08-16 20:53:51 +00:00
|
|
|
ci_logs_args,
|
2023-08-12 20:53:33 +00:00
|
|
|
docker_image,
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-11-02 13:38:55 +00:00
|
|
|
logging.info("Going to run %s", run_command)
|
|
|
|
|
2023-09-27 14:27:37 +00:00
|
|
|
run_log_path = temp_path / "run.log"
|
|
|
|
main_log_path = workspace_path / "main.log"
|
2023-08-13 04:35:32 +00:00
|
|
|
|
2023-08-16 20:53:51 +00:00
|
|
|
with TeePopen(run_command, run_log_path) as process:
|
|
|
|
retcode = process.wait()
|
|
|
|
if retcode == 0:
|
|
|
|
logging.info("Run successfully")
|
|
|
|
else:
|
|
|
|
logging.info("Run failed")
|
2021-11-02 13:38:55 +00:00
|
|
|
|
|
|
|
subprocess.check_call(f"sudo chown -R ubuntu:ubuntu {temp_path}", shell=True)
|
2023-09-27 14:27:37 +00:00
|
|
|
ci_logs_credentials.clean_ci_logs_from_credentials(run_log_path)
|
2023-08-12 22:19:58 +00:00
|
|
|
|
2021-11-02 13:38:55 +00:00
|
|
|
paths = {
|
2022-12-26 15:29:32 +00:00
|
|
|
"run.log": run_log_path,
|
2023-08-13 04:32:48 +00:00
|
|
|
"main.log": main_log_path,
|
2023-09-27 14:27:37 +00:00
|
|
|
"fuzzer.log": workspace_path / "fuzzer.log",
|
|
|
|
"report.html": workspace_path / "report.html",
|
|
|
|
"core.zst": workspace_path / "core.zst",
|
|
|
|
"dmesg.log": workspace_path / "dmesg.log",
|
2021-11-02 13:38:55 +00:00
|
|
|
}
|
|
|
|
|
2023-09-27 14:27:37 +00:00
|
|
|
compressed_server_log_path = workspace_path / "server.log.zst"
|
|
|
|
if compressed_server_log_path.exists():
|
2023-08-13 00:38:48 +00:00
|
|
|
paths["server.log.zst"] = compressed_server_log_path
|
|
|
|
|
|
|
|
# The script can fail before the invocation of `zstd`, but we are still interested in its log:
|
|
|
|
|
2023-09-27 14:27:37 +00:00
|
|
|
not_compressed_server_log_path = workspace_path / "server.log"
|
|
|
|
if not_compressed_server_log_path.exists():
|
2023-08-13 00:38:48 +00:00
|
|
|
paths["server.log"] = not_compressed_server_log_path
|
|
|
|
|
2021-11-02 13:38:55 +00:00
|
|
|
# Try to get status message saved by the fuzzer
|
|
|
|
try:
|
2023-09-27 14:27:37 +00:00
|
|
|
with open(workspace_path / "status.txt", "r", encoding="utf-8") as status_f:
|
2022-03-22 16:39:58 +00:00
|
|
|
status = status_f.readline().rstrip("\n")
|
|
|
|
|
2023-09-27 14:27:37 +00:00
|
|
|
with open(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")
|
2021-11-02 13:38:55 +00:00
|
|
|
except:
|
2022-03-22 16:39:58 +00:00
|
|
|
status = "failure"
|
|
|
|
description = "Task failed: $?=" + str(retcode)
|
2021-11-02 13:38:55 +00:00
|
|
|
|
2024-01-04 15:35:09 +00:00
|
|
|
JobReport(
|
|
|
|
description=description,
|
|
|
|
test_results=[],
|
|
|
|
status=status,
|
|
|
|
start_time=stopwatch.start_time_str,
|
|
|
|
duration=stopwatch.duration_seconds,
|
|
|
|
# test generates its own report.html
|
|
|
|
additional_files=[v for _, v in paths.items()],
|
|
|
|
).dump()
|
|
|
|
|
|
|
|
logging.info("Result: '%s', '%s'", status, description)
|
|
|
|
if status == "failure":
|
|
|
|
sys.exit(1)
|
2023-04-06 10:46:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|