ClickHouse/tests/ci/split_build_smoke_check.py

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

155 lines
4.8 KiB
Python
Raw Normal View History

2021-11-11 13:57:17 +00:00
#!/usr/bin/env python3
import os
import logging
import subprocess
2021-12-01 14:23:51 +00:00
import sys
2021-11-11 13:57:17 +00:00
from github import Github
2022-08-11 13:01:32 +00:00
from env_helper import TEMP_PATH, REPO_COPY, REPORTS_PATH
2021-11-11 13:57:17 +00:00
from s3_helper import S3Helper
from get_robot_token import get_best_robot_token
2021-11-26 14:00:09 +00:00
from pr_info import PRInfo
2021-11-12 11:11:44 +00:00
from build_download_helper import download_shared_build
2021-11-12 11:39:00 +00:00
from upload_result_helper import upload_results
2021-11-12 12:13:13 +00:00
from docker_pull_helper import get_image_with_version
2021-11-12 12:36:25 +00:00
from commit_status_helper import post_commit_status
2021-11-19 14:47:04 +00:00
from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse
from stopwatch import Stopwatch
2021-12-01 14:23:51 +00:00
from rerun_helper import RerunHelper
2021-11-19 14:47:04 +00:00
2021-11-11 13:57:17 +00:00
DOCKER_IMAGE = "clickhouse/split-build-smoke-test"
DOWNLOAD_RETRIES_COUNT = 5
2021-11-12 09:33:22 +00:00
RESULT_LOG_NAME = "run.log"
CHECK_NAME = "Split build smoke test"
2021-11-11 13:57:17 +00:00
def process_result(result_folder, server_log_folder):
status = "success"
description = "Server started and responded"
2021-11-11 13:57:17 +00:00
summary = [("Smoke test", "OK")]
with open(os.path.join(result_folder, RESULT_LOG_NAME), "r") as run_log:
lines = run_log.read().split("\n")
if not lines or lines[0].strip() != "OK":
2021-11-11 13:57:17 +00:00
status = "failure"
logging.info("Lines is not ok: %s", str("\n".join(lines)))
2021-11-11 13:57:17 +00:00
summary = [("Smoke test", "FAIL")]
description = "Server failed to respond, see result in logs"
2021-11-11 13:57:17 +00:00
result_logs = []
server_log_path = os.path.join(server_log_folder, "clickhouse-server.log")
2021-11-12 09:33:22 +00:00
stderr_log_path = os.path.join(result_folder, "stderr.log")
client_stderr_log_path = os.path.join(result_folder, "clientstderr.log")
run_log_path = os.path.join(result_folder, RESULT_LOG_NAME)
2021-11-11 13:57:17 +00:00
for path in [
server_log_path,
stderr_log_path,
client_stderr_log_path,
run_log_path,
]:
2021-11-12 09:33:22 +00:00
if os.path.exists(path):
result_logs.append(path)
2021-11-11 13:57:17 +00:00
return status, description, summary, result_logs
2021-11-11 13:57:17 +00:00
def get_run_command(build_path, result_folder, server_log_folder, docker_image):
return (
f"docker run --network=host --volume={build_path}:/package_folder"
f" --volume={server_log_folder}:/var/log/clickhouse-server"
f" --volume={result_folder}:/test_output"
f" {docker_image} >{result_folder}/{RESULT_LOG_NAME}"
)
2021-11-11 13:57:17 +00:00
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
2021-11-19 14:47:04 +00:00
stopwatch = Stopwatch()
2021-11-26 14:00:09 +00:00
temp_path = TEMP_PATH
repo_path = REPO_COPY
reports_path = REPORTS_PATH
2021-11-11 13:57:17 +00:00
2021-11-26 14:00:09 +00:00
pr_info = PRInfo()
2021-11-11 13:57:17 +00:00
gh = Github(get_best_robot_token(), per_page=100)
2021-11-11 13:57:17 +00:00
2021-12-01 14:23:51 +00:00
rerun_helper = RerunHelper(gh, pr_info, CHECK_NAME)
if rerun_helper.is_already_finished_by_status():
logging.info("Check is already finished according to github status, exiting")
sys.exit(0)
2021-11-11 13:57:17 +00:00
for root, _, files in os.walk(reports_path):
for f in files:
if f == "changed_images.json":
images_path = os.path.join(root, "changed_images.json")
2021-11-11 13:57:17 +00:00
break
2021-11-12 12:13:13 +00:00
docker_image = get_image_with_version(reports_path, DOCKER_IMAGE)
2021-11-11 13:57:17 +00:00
packages_path = os.path.join(temp_path, "packages")
if not os.path.exists(packages_path):
os.makedirs(packages_path)
2021-11-12 11:11:44 +00:00
download_shared_build(CHECK_NAME, reports_path, packages_path)
2021-11-11 13:57:17 +00:00
server_log_path = os.path.join(temp_path, "server_log")
if not os.path.exists(server_log_path):
os.makedirs(server_log_path)
result_path = os.path.join(temp_path, "result_path")
if not os.path.exists(result_path):
os.makedirs(result_path)
run_command = get_run_command(
packages_path, result_path, server_log_path, docker_image
)
2021-11-11 13:57:17 +00:00
logging.info("Going to run command %s", run_command)
with subprocess.Popen(run_command, shell=True) 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)
2021-11-11 19:42:59 +00:00
print("Result path", os.listdir(result_path))
print("Server log path", os.listdir(server_log_path))
2021-11-11 13:57:17 +00:00
state, description, test_results, additional_logs = process_result(
result_path, server_log_path
)
2021-11-11 13:57:17 +00:00
2021-11-19 14:47:04 +00:00
ch_helper = ClickHouseHelper()
2022-08-11 13:01:32 +00:00
s3_helper = S3Helper()
report_url = upload_results(
s3_helper,
pr_info.number,
pr_info.sha,
test_results,
additional_logs,
CHECK_NAME,
)
2021-11-11 13:57:17 +00:00
print(f"::notice ::Report url: {report_url}")
2021-11-15 07:07:03 +00:00
post_commit_status(gh, pr_info.sha, CHECK_NAME, description, state, report_url)
2021-11-19 14:47:04 +00:00
prepared_events = prepare_tests_results_for_clickhouse(
pr_info,
test_results,
state,
stopwatch.duration_seconds,
stopwatch.start_time_str,
report_url,
CHECK_NAME,
)
2022-03-29 19:06:50 +00:00
ch_helper.insert_events_into(db="default", table="checks", events=prepared_events)
2022-03-29 12:41:47 +00:00
if state == "error":
sys.exit(1)