import pytest
from helpers.cluster import ClickHouseCluster
from helpers.client import QueryRuntimeException
cluster = ClickHouseCluster(__file__)
node1 = cluster.add_instance(
"node1", user_configs=["configs/config_no_substs.xml"]
) # hardcoded value 33333
node2 = cluster.add_instance(
"node2",
user_configs=["configs/config_env.xml"],
env_variables={"MAX_QUERY_SIZE": "55555"},
)
node3 = cluster.add_instance(
"node3", user_configs=["configs/config_zk.xml"], with_zookeeper=True
)
node4 = cluster.add_instance(
"node4",
user_configs=["configs/config_incl.xml"],
main_configs=["configs/include_from_source.xml"],
) # include value 77777
node5 = cluster.add_instance(
"node5", user_configs=["configs/config_allow_databases.xml"]
)
node6 = cluster.add_instance(
"node6",
user_configs=["configs/config_include_from_env.xml"],
env_variables={
"INCLUDE_FROM_ENV": "/etc/clickhouse-server/config.d/include_from_source.xml"
},
main_configs=["configs/include_from_source.xml"],
)
node7 = cluster.add_instance(
"node7",
user_configs=[
"configs/000-config_with_env_subst.xml",
"configs/010-env_subst_override.xml",
],
env_variables={
# overridden with 424242
"MAX_QUERY_SIZE": "121212",
"MAX_THREADS": "2",
},
instance_env_variables=True,
)
@pytest.fixture(scope="module")
def start_cluster():
try:
def create_zk_roots(zk):
zk.create(path="/setting/max_query_size", value=b"77777", makepath=True)
zk.create(
path="/users_from_zk_1",
value=b"default",
makepath=True,
)
zk.create(
path="/users_from_zk_2",
value=b"default",
makepath=True,
)
cluster.add_zookeeper_startup_command(create_zk_roots)
cluster.start()
yield cluster
finally:
cluster.shutdown()
def test_config(start_cluster):
assert (
node1.query("select value from system.settings where name = 'max_query_size'")
== "33333\n"
)
assert (
node2.query("select value from system.settings where name = 'max_query_size'")
== "55555\n"
)
assert (
node3.query("select value from system.settings where name = 'max_query_size'")
== "77777\n"
)
assert (
node4.query("select value from system.settings where name = 'max_query_size'")
== "99999\n"
)
assert (
node6.query("select value from system.settings where name = 'max_query_size'")
== "99999\n"
)
assert (
node7.query("select value from system.settings where name = 'max_query_size'")
== "424242\n"
)
assert (
node7.query("select value from system.settings where name = 'max_threads'")
== "2\n"
)
def test_config_invalid_overrides(start_cluster):
node7.replace_config(
"/etc/clickhouse-server/users.d/000-config_with_env_subst.xml",
"""
100
default
default
""",
)
with pytest.raises(
QueryRuntimeException,
match="Failed to preprocess config '/etc/clickhouse-server/users.xml': Exception: Element has value and does not have 'replace' attribute, can't process from_env substitution",
):
node7.query("SYSTEM RELOAD CONFIG")
node7.replace_config(
"/etc/clickhouse-server/users.d/000-config_with_env_subst.xml",
"""
1
default
default
""",
)
node7.query("SYSTEM RELOAD CONFIG")
def test_include_config(start_cluster):
#
assert node4.query("select 1")
assert node4.query("select 1", user="user_1")
assert node4.query("select 1", user="user_2")
#