2018-11-23 15:10:07 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#-*- coding: utf-8 -*-
|
|
|
|
import subprocess
|
|
|
|
import os
|
2018-12-07 14:08:25 +00:00
|
|
|
import getpass
|
2018-11-23 15:10:07 +00:00
|
|
|
import argparse
|
|
|
|
import logging
|
2018-12-07 14:08:25 +00:00
|
|
|
import signal
|
|
|
|
import subprocess
|
2019-05-20 09:48:36 +00:00
|
|
|
import sys
|
2018-11-23 15:10:07 +00:00
|
|
|
|
2018-12-07 14:08:25 +00:00
|
|
|
CUR_FILE_DIR = os.path.dirname(os.path.realpath(__file__))
|
2020-04-06 18:30:51 +00:00
|
|
|
DEFAULT_CLICKHOUSE_ROOT = os.path.abspath(os.path.join(CUR_FILE_DIR, "../../"))
|
2018-12-07 14:08:25 +00:00
|
|
|
CURRENT_WORK_DIR = os.getcwd()
|
|
|
|
CONTAINER_NAME = "clickhouse_integration_tests"
|
2018-11-23 15:10:07 +00:00
|
|
|
|
2020-06-29 11:19:06 +00:00
|
|
|
CONFIG_DIR_IN_REPO = "programs/server"
|
|
|
|
INTERGATION_DIR_IN_REPO = "tests/integration"
|
|
|
|
|
2018-11-23 15:10:07 +00:00
|
|
|
DIND_INTEGRATION_TESTS_IMAGE_NAME = "yandex/clickhouse-integration-tests-runner"
|
|
|
|
|
2018-12-07 14:08:25 +00:00
|
|
|
def check_args_and_update_paths(args):
|
2020-06-29 11:19:06 +00:00
|
|
|
if args.clickhouse_root:
|
|
|
|
if not ps.path.isabs(args.clickhouse_root):
|
|
|
|
CLICKHOUSE_ROOT = os.path.abspath(args.clickhouse_root)
|
|
|
|
else:
|
|
|
|
CLICKHOUSE_ROOT = args.clickhouse_root
|
|
|
|
else:
|
|
|
|
logging.info("ClickHouse root is not set. Will use {}".format(DEFAULT_CLICKHOUSE_ROOT))
|
|
|
|
CLICKHOUSE_ROOT = DEFAULT_CLICKHOUSE_ROOT
|
|
|
|
|
2018-12-07 14:08:25 +00:00
|
|
|
if not os.path.isabs(args.binary):
|
|
|
|
args.binary = os.path.abspath(os.path.join(CURRENT_WORK_DIR, args.binary))
|
|
|
|
|
2019-12-12 15:10:09 +00:00
|
|
|
if not args.bridge_binary:
|
|
|
|
args.bridge_binary = os.path.join(os.path.dirname(args.binary), 'clickhouse-odbc-bridge')
|
|
|
|
elif not os.path.isabs(args.bridge_binary):
|
|
|
|
args.bridge_binary = os.path.abspath(os.path.join(CURRENT_WORK_DIR, args.bridge_binary))
|
|
|
|
|
2020-06-29 11:19:06 +00:00
|
|
|
if args.base_configs_dir:
|
|
|
|
if not os.path.isabs(args.base_configs_dir):
|
|
|
|
args.base_configs_dir = os.path.abspath(os.path.join(CURRENT_WORK_DIR, args.base_configs_dir))
|
|
|
|
else:
|
|
|
|
args.base_configs_dir = os.path.abspath(os.path.join(CLICKHOUSE_ROOT, CONFIG_DIR_IN_REPO))
|
|
|
|
logging.info("Base configs dir is not set. Will use {}".format(args.base_configs_dir))
|
2018-12-07 14:08:25 +00:00
|
|
|
|
2020-06-29 11:19:06 +00:00
|
|
|
if args.cases_dir:
|
|
|
|
if not os.path.isabs(args.cases_dir):
|
|
|
|
args.cases_dir = os.path.abspath(os.path.join(CURRENT_WORK_DIR, args.cases_dir))
|
|
|
|
else:
|
|
|
|
args.cases_dir = os.path.abspath(os.path.join(CLICKHOUSE_ROOT, INTERGATION_DIR_IN_REPO))
|
|
|
|
logging.info("Cases dir is not set. Will use {}".format(args.cases_dir))
|
2018-12-07 14:08:25 +00:00
|
|
|
|
2020-06-29 11:19:06 +00:00
|
|
|
logging.info("base_configs_dir: {}, binary: {}, cases_dir: {} ".format(args.base_configs_dir, args.binary, args.cases_dir))
|
|
|
|
|
|
|
|
for path in [args.binary, args.base_configs_dir, args.cases_dir, CLICKHOUSE_ROOT]:
|
2018-12-07 14:08:25 +00:00
|
|
|
if not os.path.exists(path):
|
2020-06-29 11:19:06 +00:00
|
|
|
raise Exception("Path {} doesn't exist".format(path))
|
|
|
|
|
|
|
|
if not os.path.exists(os.path.join(args.base_configs_dir, "config.xml")):
|
|
|
|
raise Exception("No configs.xml in {}".format(args.base_configs_dir))
|
|
|
|
|
|
|
|
if not os.path.exists(os.path.join(args.base_configs_dir, "users.xml")):
|
|
|
|
raise Exception("No users.xml in {}".format(args.base_configs_dir))
|
2018-12-07 14:08:25 +00:00
|
|
|
|
|
|
|
def docker_kill_handler_handler(signum, frame):
|
|
|
|
subprocess.check_call('docker kill $(docker ps -a -q --filter name={name} --format="{{{{.ID}}}}")'.format(name=CONTAINER_NAME), shell=True)
|
|
|
|
raise KeyboardInterrupt("Killed by Ctrl+C")
|
|
|
|
|
|
|
|
signal.signal(signal.SIGINT, docker_kill_handler_handler)
|
|
|
|
|
2020-06-29 11:19:06 +00:00
|
|
|
# Integration tests runner should allow to run tests on several versions of ClickHouse.
|
|
|
|
# Integration tests should be portable.
|
|
|
|
# To run integration tests following artfacts should be sufficient:
|
|
|
|
# - clickhouse binaries (env CLICKHOUSE_TESTS_SERVER_BIN_PATH or --binary arg)
|
|
|
|
# - clickhouse default configs(config.xml, users.xml) from same version as binary (env CLICKHOUSE_TESTS_BASE_CONFIG_DIR or --base-configs-dir arg)
|
|
|
|
# - odbc bridge binary (env CLICKHOUSE_TESTS_ODBC_BRIDGE_BIN_PATH or --bridge-binary arg)
|
|
|
|
# - tests/integration directory with all test cases and configs (env CLICKHOUSE_TESTS_INTEGRATION_PATH or --cases-dir)
|
|
|
|
#
|
|
|
|
# 1) --clickhouse-root is only used to determine other paths on default places
|
|
|
|
# 2) path of runner script is used to determine paths for trivial case, when we run it from repository
|
|
|
|
|
2018-11-23 15:10:07 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
|
|
|
|
parser = argparse.ArgumentParser(description="ClickHouse integration tests runner")
|
2018-12-07 14:08:25 +00:00
|
|
|
|
2018-11-23 15:10:07 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--binary",
|
|
|
|
default=os.environ.get("CLICKHOUSE_TESTS_SERVER_BIN_PATH", os.environ.get("CLICKHOUSE_TESTS_CLIENT_BIN_PATH", "/usr/bin/clickhouse")),
|
2020-06-29 11:19:06 +00:00
|
|
|
help="Path to clickhouse binary. For example /usr/bin/clickhouse")
|
2018-12-07 14:08:25 +00:00
|
|
|
|
2019-01-30 08:24:16 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--bridge-binary",
|
2019-12-12 15:10:09 +00:00
|
|
|
default=os.environ.get("CLICKHOUSE_TESTS_ODBC_BRIDGE_BIN_PATH", ""),
|
|
|
|
help="Path to clickhouse-odbc-bridge binary. Defaults to clickhouse-odbc-bridge in the same dir as clickhouse.")
|
2019-01-30 08:24:16 +00:00
|
|
|
|
2018-11-23 15:10:07 +00:00
|
|
|
parser.add_argument(
|
2020-06-29 11:19:06 +00:00
|
|
|
"--base-configs-dir",
|
|
|
|
default=os.environ.get("CLICKHOUSE_TESTS_BASE_CONFIG_DIR"),
|
|
|
|
help="Path to clickhouse base configs directory with config.xml/users.xml")
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--cases-dir",
|
|
|
|
default=os.environ.get("CLICKHOUSE_TESTS_INTEGRATION_PATH"),
|
|
|
|
help="Path to integration tests cases and configs directory. For example tests/integration in repository")
|
2018-12-07 14:08:25 +00:00
|
|
|
|
2018-11-23 15:10:07 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--clickhouse-root",
|
2020-06-29 11:19:06 +00:00
|
|
|
help="Path to repository root folder. Used to take configuration from repository default paths.")
|
2018-12-07 14:08:25 +00:00
|
|
|
|
2019-05-20 08:11:53 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--command",
|
|
|
|
default='',
|
|
|
|
help="Set it to run some other command in container (for example bash)")
|
|
|
|
|
2018-11-26 10:23:03 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--disable-net-host",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
2018-12-07 14:08:25 +00:00
|
|
|
help="Don't use net host in parent docker container")
|
2018-11-26 10:23:03 +00:00
|
|
|
|
2020-06-30 13:08:12 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--docker-image-version",
|
|
|
|
default="latest",
|
|
|
|
help="Version of docker image which runner will use to run tests")
|
|
|
|
|
|
|
|
|
2018-11-23 15:10:07 +00:00
|
|
|
parser.add_argument('pytest_args', nargs='*', help="args for pytest command")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2018-12-07 14:08:25 +00:00
|
|
|
check_args_and_update_paths(args)
|
|
|
|
|
2018-11-26 10:23:03 +00:00
|
|
|
net = ""
|
|
|
|
if not args.disable_net_host:
|
|
|
|
net = "--net=host"
|
|
|
|
|
2019-05-20 08:11:53 +00:00
|
|
|
# create named volume which will be used inside to store images and other docker related files,
|
|
|
|
# to avoid redownloading it every time
|
|
|
|
#
|
|
|
|
# should be removed manually when not needed
|
|
|
|
subprocess.check_call('docker volume create {name}_volume'.format(name=CONTAINER_NAME), shell=True)
|
|
|
|
|
2019-05-20 09:48:36 +00:00
|
|
|
# enable tty mode & interactive for docker if we have real tty
|
|
|
|
tty = ""
|
|
|
|
if sys.stdout.isatty() and sys.stdin.isatty():
|
|
|
|
tty = "-it"
|
|
|
|
|
|
|
|
cmd = "docker run {net} {tty} --rm --name {name} --privileged --volume={bridge_bin}:/clickhouse-odbc-bridge --volume={bin}:/clickhouse \
|
2020-06-29 11:19:06 +00:00
|
|
|
--volume={base_cfg}:/clickhouse-base-config --volume={cases_dir}:/ClickHouse/tests/integration \
|
|
|
|
--volume={name}_volume:/var/lib/docker -e PYTEST_OPTS='{opts}' {img} {command}".format(
|
2018-11-26 10:23:03 +00:00
|
|
|
net=net,
|
2019-05-20 09:48:36 +00:00
|
|
|
tty=tty,
|
2018-11-23 15:10:07 +00:00
|
|
|
bin=args.binary,
|
2019-01-30 08:24:16 +00:00
|
|
|
bridge_bin=args.bridge_binary,
|
2020-06-29 11:19:06 +00:00
|
|
|
base_cfg=args.base_configs_dir,
|
|
|
|
cases_dir=args.cases_dir,
|
2018-11-23 15:10:07 +00:00
|
|
|
opts=' '.join(args.pytest_args),
|
2020-06-30 13:08:12 +00:00
|
|
|
img=DIND_INTEGRATION_TESTS_IMAGE_NAME + ":" + args.docker_image_version,
|
2018-12-07 14:08:25 +00:00
|
|
|
name=CONTAINER_NAME,
|
2019-05-20 08:11:53 +00:00
|
|
|
command=args.command
|
2018-11-23 15:10:07 +00:00
|
|
|
)
|
|
|
|
|
2019-12-12 15:10:09 +00:00
|
|
|
print("Running pytest container as: '" + cmd + "'.")
|
2019-07-21 11:45:01 +00:00
|
|
|
subprocess.check_call(cmd, shell=True)
|