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
|
2023-01-03 14:23:19 +00:00
|
|
|
from pathlib import Path
|
2023-12-18 08:07:22 +00:00
|
|
|
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
|
2024-01-29 17:13:32 +00:00
|
|
|
from pr_info import PRInfo
|
2024-05-16 18:06:03 +00:00
|
|
|
from report import ERROR, FAILURE, SUCCESS, JobReport, TestResults, read_test_results
|
2023-01-03 14:23:19 +00:00
|
|
|
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
|
|
|
|
2022-08-10 18:21:15 +00:00
|
|
|
# Will help to avoid errors like _csv.Error: field larger than field limit (131072)
|
|
|
|
csv.field_size_limit(sys.maxsize)
|
|
|
|
|
2022-02-15 23:44:44 +00:00
|
|
|
|
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:
|
2022-02-15 23:44:44 +00:00
|
|
|
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
|
2022-02-15 23:44:44 +00:00
|
|
|
f"-e FASTTEST_WORKSPACE=/fasttest-workspace -e FASTTEST_OUTPUT=/test_output "
|
2024-08-09 14:22:33 +00:00
|
|
|
f"-e FASTTEST_SOURCE=/repo "
|
2023-03-29 14:52:04 +00:00
|
|
|
f"-e FASTTEST_CMAKE_FLAGS='-DCOMPILER_CACHE=sccache' "
|
2022-02-15 23:44:44 +00:00
|
|
|
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"
|
2022-02-15 23:44:44 +00:00
|
|
|
)
|
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]:
|
2023-01-03 14:23:19 +00:00
|
|
|
test_results = [] # type: TestResults
|
2023-09-22 11:16:46 +00:00
|
|
|
# Just upload all files from result_directory.
|
2022-02-15 23:44:44 +00:00
|
|
|
# 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():
|
2023-12-11 21:42:41 +00:00
|
|
|
logging.info("Found %s", status_path.name)
|
2022-02-15 23:44:44 +00:00
|
|
|
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))
|
2024-02-06 12:39:34 +00:00
|
|
|
return ERROR, "Invalid check_status.tsv", test_results
|
2021-10-22 09:26:39 +00:00
|
|
|
state, description = status[0][0], status[0][1]
|
|
|
|
|
2022-12-14 14:05:22 +00:00
|
|
|
try:
|
2023-09-22 11:16:46 +00:00
|
|
|
results_path = result_directory / "test_results.tsv"
|
2022-12-14 14:05:22 +00:00
|
|
|
test_results = read_test_results(results_path)
|
|
|
|
if len(test_results) == 0:
|
2024-02-06 12:39:34 +00:00
|
|
|
return ERROR, "Empty test_results.tsv", test_results
|
2022-12-14 14:05:22 +00:00
|
|
|
except Exception as e:
|
2024-02-06 12:39:34 +00:00
|
|
|
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
|
|
|
|
2023-01-03 14:23:19 +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
|
|
|
|
2023-12-18 08:07:22 +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
|
|
|
|
2022-02-15 23:44:44 +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
|
|
|
|
2024-05-16 18:06:03 +00:00
|
|
|
with TeePopen(run_cmd, run_log_path) as process:
|
2023-09-06 11:59:51 +00:00
|
|
|
retcode = process.wait()
|
2024-05-16 18:06:03 +00:00
|
|
|
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
|
|
|
|
2022-02-15 23:44:44 +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
|
2022-02-15 23:44:44 +00:00
|
|
|
if "submodule_log.txt" not in test_output_files:
|
2021-10-22 09:26:39 +00:00
|
|
|
description = "Cannot clone repository"
|
2024-02-06 12:39:34 +00:00
|
|
|
state = FAILURE
|
2022-02-15 23:44:44 +00:00
|
|
|
elif "cmake_log.txt" not in test_output_files:
|
2021-10-22 09:26:39 +00:00
|
|
|
description = "Cannot fetch submodules"
|
2024-02-06 12:39:34 +00:00
|
|
|
state = FAILURE
|
2022-02-15 23:44:44 +00:00
|
|
|
elif "build_log.txt" not in test_output_files:
|
2021-10-22 09:26:39 +00:00
|
|
|
description = "Cannot finish cmake"
|
2024-02-06 12:39:34 +00:00
|
|
|
state = FAILURE
|
2022-02-15 23:44:44 +00:00
|
|
|
elif "install_log.txt" not in test_output_files:
|
2021-10-22 09:26:39 +00:00
|
|
|
description = "Cannot build ClickHouse"
|
2024-02-06 12:39:34 +00:00
|
|
|
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"
|
2024-02-06 12:39:34 +00:00
|
|
|
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
|
|
|
|
2024-01-04 15:35:09 +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
|
2024-02-06 12:39:34 +00:00
|
|
|
if state != SUCCESS:
|
2024-01-29 17:13:32 +00:00
|
|
|
sys.exit(1)
|
2023-01-03 14:23:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|