Fix test.

This commit is contained in:
Sergey V. Galtsev 2018-12-19 23:29:52 +03:00
parent f9869b7d7e
commit acb8cf1849
3 changed files with 38 additions and 10 deletions

View File

@ -7,5 +7,8 @@
<stdout>/var/log/clickhouse-server/stdout.log</stdout> <stdout>/var/log/clickhouse-server/stdout.log</stdout>
</logger> </logger>
<path>/var/lib/clickhouse/</path>
<mark_cache_size>5368709120</mark_cache_size>
<users_config>users.xml</users_config> <users_config>users.xml</users_config>
</yandex> </yandex>

View File

@ -1,3 +1,23 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<yandex> <yandex>
<profiles>
<default>
</default>
</profiles>
<users>
<default>
<password></password>
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</default>
</users>
<quotas>
<default>
</default>
</quotas>
</yandex> </yandex>

View File

@ -1,3 +1,4 @@
import docker
import os import os
import pwd import pwd
import pytest import pytest
@ -6,32 +7,36 @@ import re
from helpers.cluster import ClickHouseCluster from helpers.cluster import ClickHouseCluster
def expect_failure_with_message(config, expected_message): def expect_failure_with_message(expected_message):
cluster = ClickHouseCluster(__file__) cluster = ClickHouseCluster(__file__)
node = cluster.add_instance('node', main_configs=[config], with_zookeeper=False) node = cluster.add_instance('node', with_zookeeper=False)
with pytest.raises(Exception): with pytest.raises(Exception):
cluster.start() cluster.start()
current_user_id = os.getuid()
other_user_id = pwd.getpwnam('nobody').pw_uid
docker_api = docker.from_env().api
container = node.get_docker_handle()
container.start()
container.exec_run('chown {0} /var/lib/clickhouse'.format(other_user_id), privileged=True)
container.exec_run('clickhouse server --config-file=/etc/clickhouse-server/config.xml --log-file=/var/log/clickhouse-server/clickhouse-server.log --errorlog-file=/var/log/clickhouse-server/clickhouse-server.err.log', privileged=True)
cluster.shutdown() # cleanup cluster.shutdown() # cleanup
with open(os.path.join(node.path, 'logs/stderr.log')) as log: with open(os.path.join(node.path, 'logs/clickhouse-server.err.log')) as log:
last_message = log.readlines()[-1].strip() last_message = log.readlines()[-1].strip()
if re.search(expected_message, last_message) is None: 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)) pytest.fail('Expected the server to fail with a message "{}", but the last message is "{}"'.format(expected_message, last_message))
def test_no_such_directory():
expect_failure_with_message('configs/no_such_directory.xml', 'Failed to stat.*no_such_directory')
def test_different_user(): def test_different_user():
current_user_id = os.getuid() current_user_id = os.getuid()
if current_user_id != 0: if current_user_id == 0:
current_user_name = pwd.getpwuid(current_user_id).pw_name current_user_name = pwd.getpwuid(current_user_id).pw_name
expect_failure_with_message( expect_failure_with_message(
'configs/owner_mismatch.xml', 'Effective user of the process \(.*\) does not match the owner of the data \(.*\)',
'Effective user of the process \(({}|{})\) does not match the owner of the data \((0|root)\)'.format(current_user_id, current_user_name),
) )