mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Add kill docker by Ctrl+C, abs path and improve readme
This commit is contained in:
parent
0b4d0978ab
commit
dbefb66691
@ -33,7 +33,12 @@ set the following environment variables:
|
|||||||
|
|
||||||
### Running with runner script
|
### Running with runner script
|
||||||
|
|
||||||
The only requirement is fresh docker.
|
The only requirement is fresh docker configured docker.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
* If you want to run integration tests without `sudo` you have to add your user to docker group `sudo usermod -aG docker $USER`. [More information](https://docs.docker.com/install/linux/linux-postinstall/) about docker configuration.
|
||||||
|
* If you already had run these tests without `./runner` script you may have problems with pytest cache. It can be removed with `rm -r __pycache__ .pytest_cache/`.
|
||||||
|
* Some tests maybe require a lot of resources (CPU, RAM, etc.). Better not try large tests like `test_cluster_copier` or `test_distributed_ddl*` on your notebook.
|
||||||
|
|
||||||
You can run tests via `./runner` script and pass pytest arguments as last arg:
|
You can run tests via `./runner` script and pass pytest arguments as last arg:
|
||||||
```
|
```
|
||||||
|
@ -2,54 +2,94 @@
|
|||||||
#-*- coding: utf-8 -*-
|
#-*- coding: utf-8 -*-
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
|
import getpass
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
import signal
|
||||||
|
import subprocess
|
||||||
|
|
||||||
CUR_FILE_DIR_PATH = os.path.dirname(os.path.realpath(__file__))
|
CUR_FILE_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||||
DEFAULT_CLICKHOUSE_ROOT = os.path.abspath(os.path.join(CUR_FILE_DIR_PATH, "../../../"))
|
DEFAULT_CLICKHOUSE_ROOT = os.path.abspath(os.path.join(CUR_FILE_DIR, "../../../"))
|
||||||
|
CURRENT_WORK_DIR = os.getcwd()
|
||||||
|
CONTAINER_NAME = "clickhouse_integration_tests"
|
||||||
|
|
||||||
DIND_INTEGRATION_TESTS_IMAGE_NAME = "yandex/clickhouse-integration-tests-runner"
|
DIND_INTEGRATION_TESTS_IMAGE_NAME = "yandex/clickhouse-integration-tests-runner"
|
||||||
|
|
||||||
|
def check_args_and_update_paths(args):
|
||||||
|
if not os.path.isabs(args.binary):
|
||||||
|
args.binary = os.path.abspath(os.path.join(CURRENT_WORK_DIR, args.binary))
|
||||||
|
|
||||||
|
if not os.path.isabs(args.configs_dir):
|
||||||
|
args.configs_dir = os.path.abspath(os.path.join(CURRENT_WORK_DIR, args.configs_dir))
|
||||||
|
|
||||||
|
if not os.path.isabs(args.clickhouse_root):
|
||||||
|
args.clickhouse_root = os.path.abspath(os.path.join(CURRENT_WORK_DIR, args.clickhouse_root))
|
||||||
|
|
||||||
|
for path in [args.binary, args.configs_dir, args.clickhouse_root]:
|
||||||
|
if not os.path.exists(path):
|
||||||
|
raise Exception("Path {} doesn't exists".format(path))
|
||||||
|
|
||||||
|
def try_rm_image():
|
||||||
|
try:
|
||||||
|
subprocess.check_call('docker rm {name}'.format(name=CONTAINER_NAME), shell=True)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
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)
|
||||||
|
try_rm_image()
|
||||||
|
raise KeyboardInterrupt("Killed by Ctrl+C")
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, docker_kill_handler_handler)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
|
||||||
parser = argparse.ArgumentParser(description="ClickHouse integration tests runner")
|
parser = argparse.ArgumentParser(description="ClickHouse integration tests runner")
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--binary",
|
"--binary",
|
||||||
default=os.environ.get("CLICKHOUSE_TESTS_SERVER_BIN_PATH", os.environ.get("CLICKHOUSE_TESTS_CLIENT_BIN_PATH", "/usr/bin/clickhouse")),
|
default=os.environ.get("CLICKHOUSE_TESTS_SERVER_BIN_PATH", os.environ.get("CLICKHOUSE_TESTS_CLIENT_BIN_PATH", "/usr/bin/clickhouse")),
|
||||||
help="Path to clickhouse binary")
|
help="Path to clickhouse binary")
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--configs-dir",
|
"--configs-dir",
|
||||||
default=os.environ.get("CLICKHOUSE_TESTS_BASE_CONFIG_DIR", "/etc/clickhouse-server"),
|
default=os.environ.get("CLICKHOUSE_TESTS_BASE_CONFIG_DIR", os.path.join(DEFAULT_CLICKHOUSE_ROOT, "dbms/programs/server")),
|
||||||
help="Path to clickhouse configs directory"
|
help="Path to clickhouse configs directory")
|
||||||
)
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--clickhouse-root",
|
"--clickhouse-root",
|
||||||
default=DEFAULT_CLICKHOUSE_ROOT,
|
default=DEFAULT_CLICKHOUSE_ROOT,
|
||||||
help="Path to repository root folder"
|
help="Path to repository root folder")
|
||||||
)
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--disable-net-host",
|
"--disable-net-host",
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help="Don't use net host in parent docker container"
|
help="Don't use net host in parent docker container")
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument('pytest_args', nargs='*', help="args for pytest command")
|
parser.add_argument('pytest_args', nargs='*', help="args for pytest command")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
check_args_and_update_paths(args)
|
||||||
|
|
||||||
net = ""
|
net = ""
|
||||||
if not args.disable_net_host:
|
if not args.disable_net_host:
|
||||||
net = "--net=host"
|
net = "--net=host"
|
||||||
|
|
||||||
cmd = "docker run {net} --privileged --volume={bin}:/clickhouse \
|
cmd = "docker run {net} --name {name} --user={user} --privileged --volume={bin}:/clickhouse \
|
||||||
--volume={cfg}:/clickhouse-config --volume={pth}:/ClickHouse -e PYTEST_OPTS='{opts}' {img}".format(
|
--volume={cfg}:/clickhouse-config --volume={pth}:/ClickHouse -e PYTEST_OPTS='{opts}' {img} ".format(
|
||||||
net=net,
|
net=net,
|
||||||
bin=args.binary,
|
bin=args.binary,
|
||||||
cfg=args.configs_dir,
|
cfg=args.configs_dir,
|
||||||
pth=args.clickhouse_root,
|
pth=args.clickhouse_root,
|
||||||
opts=' '.join(args.pytest_args),
|
opts=' '.join(args.pytest_args),
|
||||||
img=DIND_INTEGRATION_TESTS_IMAGE_NAME,
|
img=DIND_INTEGRATION_TESTS_IMAGE_NAME,
|
||||||
|
user=getpass.getuser(),
|
||||||
|
name=CONTAINER_NAME,
|
||||||
)
|
)
|
||||||
|
|
||||||
subprocess.check_call(cmd, shell=True)
|
try:
|
||||||
|
subprocess.check_call(cmd, shell=True)
|
||||||
|
finally:
|
||||||
|
try_rm_image()
|
||||||
|
Loading…
Reference in New Issue
Block a user