mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
fix killall. better test_different_user
This commit is contained in:
parent
ad2376c03b
commit
9345b93486
@ -1778,7 +1778,7 @@ CLICKHOUSE_START_COMMAND = "clickhouse server --config-file=/etc/clickhouse-serv
|
||||
" --log-file=/var/log/clickhouse-server/clickhouse-server.log " \
|
||||
" --errorlog-file=/var/log/clickhouse-server/clickhouse-server.err.log"
|
||||
|
||||
CLICKHOUSE_STAY_ALIVE_COMMAND = 'bash -c "trap \'killall tail\' INT TERM; {} --daemon; coproc tail -f /dev/null; wait $$!"'.format(CLICKHOUSE_START_COMMAND)
|
||||
CLICKHOUSE_STAY_ALIVE_COMMAND = 'bash -c "trap \'pkill tail\' INT TERM; {} --daemon; coproc tail -f /dev/null; wait $$!"'.format(CLICKHOUSE_START_COMMAND)
|
||||
|
||||
# /run/xtables.lock passed inside for correct iptables --wait
|
||||
DOCKER_COMPOSE_TEMPLATE = '''
|
||||
@ -2096,7 +2096,7 @@ class ClickHouseInstance:
|
||||
return
|
||||
except Exception as e:
|
||||
logging.warning(f"Current start attempt failed. Will kill {pid} just in case.")
|
||||
self.exec_in_container(["bash", "-c", f"kill -9 {pid}"], user='root')
|
||||
self.exec_in_container(["bash", "-c", f"kill -9 {pid}"], user='root', nothrow=True)
|
||||
time.sleep(time_to_sleep)
|
||||
|
||||
raise Exception("Cannot start ClickHouse, see additional info in logs")
|
||||
|
@ -2,16 +2,16 @@ import os
|
||||
import pwd
|
||||
import re
|
||||
import pytest
|
||||
from helpers.cluster import ClickHouseCluster, CLICKHOUSE_START_COMMAND
|
||||
from helpers.cluster import ClickHouseCluster
|
||||
|
||||
cluster = ClickHouseCluster(__file__)
|
||||
node = cluster.add_instance('node')
|
||||
node = cluster.add_instance('node', stay_alive=True)
|
||||
other_user_id = pwd.getpwnam('nobody').pw_uid
|
||||
current_user_id = os.getuid()
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def started_cluster():
|
||||
try:
|
||||
current_user_id = os.getuid()
|
||||
if current_user_id != 0:
|
||||
return
|
||||
|
||||
@ -22,25 +22,17 @@ def started_cluster():
|
||||
cluster.shutdown(ignore_fatal=True)
|
||||
|
||||
|
||||
def test_different_user():
|
||||
def test_different_user(started_cluster):
|
||||
with pytest.raises(Exception):
|
||||
node.stop_clickhouse()
|
||||
node.exec_in_container(["bash", "-c", f"chown {other_user_id} /var/lib/clickhouse"], privileged=True)
|
||||
node.start_clickhouse(start_wait_sec=3)
|
||||
|
||||
container = node.get_docker_handle()
|
||||
container.stop()
|
||||
container.start()
|
||||
container.exec_run('chown {} /var/lib/clickhouse'.format(other_user_id), privileged=True)
|
||||
container.exec_run(CLICKHOUSE_START_COMMAND)
|
||||
container.exec_run('sleep 1') # Without sleep logs can not be flushed before check
|
||||
with open(os.path.join(node.path, 'logs/clickhouse-server.err.log')) as log:
|
||||
expected_message = "Effective user of the process \(.*\) does not match the owner of the data \(.*\)\. Run under 'sudo -u .*'\."
|
||||
last_message = ""
|
||||
for line in log:
|
||||
if "Effective" in line:
|
||||
last_message = line
|
||||
|
||||
if re.search(expected_message, last_message) is None:
|
||||
pytest.fail(
|
||||
'Expected the server to fail with a message "{}", but the last message is "{}"'.format(expected_message,
|
||||
last_message))
|
||||
container.exec_run('chown clickhouse /var/lib/clickhouse', privileged=True)
|
||||
container.exec_run(CLICKHOUSE_START_COMMAND)
|
||||
log = node.grep_in_log("Effective")
|
||||
expected_message = "Effective user of the process \(.*\) does not match the owner of the data \(.*\)\. Run under 'sudo -u .*'\."
|
||||
if re.search(expected_message, log) is None:
|
||||
pytest.fail(
|
||||
'Expected the server to fail with a message "{}", but the last message is "{}"'.format(expected_message, log))
|
||||
node.exec_in_container(["bash", "-c", f"chown {current_user_id} /var/lib/clickhouse"], privileged=True)
|
||||
node.start_clickhouse()
|
||||
node.rotate_logs()
|
||||
|
Loading…
Reference in New Issue
Block a user