ClickHouse/tests/ci/fast_test_check.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

160 lines
5.4 KiB
Python
Raw Normal View History

2021-10-22 09:26:39 +00:00
#!/usr/bin/env python3
2024-01-30 17:29:55 +00:00
import csv
2021-10-22 09:26:39 +00:00
import logging
import os
2024-01-30 17:29:55 +00:00
import subprocess
2021-11-25 10:11:47 +00:00
import sys
from pathlib import Path
from typing import Tuple
from docker_images_helper import DockerImage, get_docker_image, pull_image
2024-01-30 17:29:55 +00:00
from env_helper import REPO_COPY, S3_BUILDS_BUCKET, TEMP_PATH
from pr_info import PRInfo
from report import ERROR, FAILURE, SUCCESS, JobReport, TestResults, read_test_results
from stopwatch import Stopwatch
2021-12-03 08:33:16 +00:00
from tee_popen import TeePopen
2021-10-22 09:26:39 +00:00
# Will help to avoid errors like _csv.Error: field larger than field limit (131072)
csv.field_size_limit(sys.maxsize)
2023-09-22 11:16:46 +00:00
def get_fasttest_cmd(
workspace: Path,
output_path: Path,
repo_path: Path,
pr_number: int,
commit_sha: str,
image: DockerImage,
) -> str:
return (
2023-09-20 17:07:42 +00:00
f"docker run --cap-add=SYS_PTRACE --user={os.geteuid()}:{os.getegid()} "
2024-02-25 22:49:25 +00:00
"--security-opt seccomp=unconfined " # required to issue io_uring sys-calls
2023-03-27 13:35:51 +00:00
"--network=host " # required to get access to IAM credentials
f"-e FASTTEST_WORKSPACE=/fasttest-workspace -e FASTTEST_OUTPUT=/test_output "
2024-08-09 14:22:33 +00:00
f"-e FASTTEST_SOURCE=/repo "
f"-e FASTTEST_CMAKE_FLAGS='-DCOMPILER_CACHE=sccache' "
f"-e PULL_REQUEST_NUMBER={pr_number} -e COMMIT_SHA={commit_sha} "
f"-e COPY_CLICKHOUSE_BINARY_TO_OUTPUT=1 "
2023-03-27 13:35:51 +00:00
f"-e SCCACHE_BUCKET={S3_BUILDS_BUCKET} -e SCCACHE_S3_KEY_PREFIX=ccache/sccache "
2023-09-20 16:02:59 +00:00
"-e stage=clone_submodules "
2024-08-09 14:22:33 +00:00
f"--volume={workspace}:/fasttest-workspace --volume={repo_path}:/repo "
f"--volume={output_path}:/test_output {image} /repo/tests/docker_scripts/fasttest_runner.sh"
)
2021-10-22 09:26:39 +00:00
2023-09-22 11:16:46 +00:00
def process_results(result_directory: Path) -> Tuple[str, str, TestResults]:
test_results = [] # type: TestResults
2023-09-22 11:16:46 +00:00
# Just upload all files from result_directory.
# If task provides processed results, then it's responsible for content of
2023-09-22 11:16:46 +00:00
# result_directory
2021-10-22 09:26:39 +00:00
2021-12-12 12:09:44 +00:00
status = []
2023-09-22 11:16:46 +00:00
status_path = result_directory / "check_status.tsv"
2023-08-29 14:35:53 +00:00
if status_path.exists():
logging.info("Found %s", status_path.name)
with open(status_path, "r", encoding="utf-8") as status_file:
status = list(csv.reader(status_file, delimiter="\t"))
2021-10-22 09:26:39 +00:00
if len(status) != 1 or len(status[0]) != 2:
2023-09-22 11:16:46 +00:00
logging.info("Files in result folder %s", os.listdir(result_directory))
return ERROR, "Invalid check_status.tsv", test_results
2021-10-22 09:26:39 +00:00
state, description = status[0][0], status[0][1]
try:
2023-09-22 11:16:46 +00:00
results_path = result_directory / "test_results.tsv"
test_results = read_test_results(results_path)
if len(test_results) == 0:
return ERROR, "Empty test_results.tsv", test_results
except Exception as e:
return (ERROR, f"Cannot parse test_results.tsv ({e})", test_results)
2021-10-22 09:26:39 +00:00
2023-09-22 11:16:46 +00:00
return state, description, test_results
2021-10-22 09:26:39 +00:00
2023-10-31 11:43:32 +00:00
def main():
2021-10-22 09:26:39 +00:00
logging.basicConfig(level=logging.INFO)
2021-11-19 14:47:04 +00:00
stopwatch = Stopwatch()
2023-10-31 11:32:08 +00:00
2023-08-29 14:35:53 +00:00
temp_path = Path(TEMP_PATH)
temp_path.mkdir(parents=True, exist_ok=True)
2021-10-22 09:26:39 +00:00
2021-11-26 14:00:09 +00:00
pr_info = PRInfo()
2021-10-22 09:26:39 +00:00
docker_image = pull_image(get_docker_image("clickhouse/fasttest"))
2021-10-22 09:26:39 +00:00
2023-08-29 14:35:53 +00:00
workspace = temp_path / "fasttest-workspace"
workspace.mkdir(parents=True, exist_ok=True)
2021-10-22 09:26:39 +00:00
2023-08-29 14:35:53 +00:00
output_path = temp_path / "fasttest-output"
output_path.mkdir(parents=True, exist_ok=True)
2021-10-22 09:26:39 +00:00
2023-09-20 16:02:59 +00:00
repo_path = Path(REPO_COPY)
2021-10-22 09:38:41 +00:00
run_cmd = get_fasttest_cmd(
workspace,
output_path,
repo_path,
pr_info.number,
pr_info.sha,
docker_image,
)
2021-10-22 09:26:39 +00:00
logging.info("Going to run fasttest with cmd %s", run_cmd)
2023-08-29 14:35:53 +00:00
logs_path = temp_path / "fasttest-logs"
logs_path.mkdir(parents=True, exist_ok=True)
2021-10-22 09:26:39 +00:00
2023-08-29 14:35:53 +00:00
run_log_path = logs_path / "run.log"
2023-10-31 11:01:49 +00:00
with TeePopen(run_cmd, run_log_path) as process:
2023-09-06 11:59:51 +00:00
retcode = process.wait()
if retcode == 0:
2023-09-06 11:59:51 +00:00
logging.info("Run successfully")
else:
logging.info("Run failed")
2021-10-22 09:26:39 +00:00
subprocess.check_call(f"sudo chown -R ubuntu:ubuntu {temp_path}", shell=True)
test_output_files = os.listdir(output_path)
2023-09-22 11:16:46 +00:00
additional_logs = [f for f in output_path.iterdir() if f.is_file()]
additional_logs.append(run_log_path)
2021-10-22 09:26:39 +00:00
test_log_exists = (
"test_log.txt" in test_output_files or "test_result.txt" in test_output_files
)
test_result_exists = "test_results.tsv" in test_output_files
2023-01-24 23:13:28 +00:00
test_results = [] # type: TestResults
if "submodule_log.txt" not in test_output_files:
2021-10-22 09:26:39 +00:00
description = "Cannot clone repository"
state = FAILURE
elif "cmake_log.txt" not in test_output_files:
2021-10-22 09:26:39 +00:00
description = "Cannot fetch submodules"
state = FAILURE
elif "build_log.txt" not in test_output_files:
2021-10-22 09:26:39 +00:00
description = "Cannot finish cmake"
state = FAILURE
elif "install_log.txt" not in test_output_files:
2021-10-22 09:26:39 +00:00
description = "Cannot build ClickHouse"
state = FAILURE
2021-10-22 09:26:39 +00:00
elif not test_log_exists and not test_result_exists:
description = "Cannot install or start ClickHouse"
state = FAILURE
2021-10-22 09:26:39 +00:00
else:
2023-09-22 11:16:46 +00:00
state, description, test_results = process_results(output_path)
2021-10-22 09:26:39 +00:00
JobReport(
description=description,
test_results=test_results,
status=state,
start_time=stopwatch.start_time_str,
duration=stopwatch.duration_seconds,
additional_files=additional_logs,
build_dir_for_upload=str(output_path / "binaries"),
).dump()
2021-11-25 09:23:45 +00:00
# Refuse other checks to run if fast test failed
if state != SUCCESS:
sys.exit(1)
if __name__ == "__main__":
main()