#!/usr/bin/env python3
import pytest
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
node1 = cluster.add_instance(
"node1", main_configs=["configs/enable_keeper1.xml"], stay_alive=True
)
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
DUPLICATE_ID_CONFIG = """
9181
1
/var/lib/clickhouse/coordination/log
/var/lib/clickhouse/coordination/snapshots
5000
10000
trace
1
node1
9234
1
node2
9234
"""
DUPLICATE_ENDPOINT_CONFIG = """
9181
1
/var/lib/clickhouse/coordination/log
/var/lib/clickhouse/coordination/snapshots
5000
10000
trace
1
node1
9234
2
node1
9234
"""
LOCALHOST_WITH_REMOTE = """
9181
1
/var/lib/clickhouse/coordination/log
/var/lib/clickhouse/coordination/snapshots
5000
10000
trace
true
1
localhost
9234
2
127.0.0.2
9234
"""
MULTIPLE_LOCAL_WITH_REMOTE = """
9181
1
/var/lib/clickhouse/coordination/log
/var/lib/clickhouse/coordination/snapshots
5000
10000
trace
true
1
127.0.0.1
9234
2
127.0.1.1
9234
3
127.0.0.2
9234
"""
NORMAL_CONFIG = """
9181
1
/var/lib/clickhouse/coordination/log
/var/lib/clickhouse/coordination/snapshots
5000
10000
trace
1
node1
9234
"""
JUST_WRONG_CONFIG = """
9181
1
/var/lib/clickhouse/coordination/log
/var/lib/clickhouse/coordination/snapshots
5000
10000
trace
1
node1
9234
2
node2
9234
3
node3
9234
"""
def test_invalid_configs(started_cluster):
node1.stop_clickhouse()
def assert_config_fails(config):
node1.replace_config(
"/etc/clickhouse-server/config.d/enable_keeper1.xml", config
)
with pytest.raises(Exception):
node1.start_clickhouse(start_wait_sec=10)
assert_config_fails(DUPLICATE_ENDPOINT_CONFIG)
assert_config_fails(DUPLICATE_ID_CONFIG)
assert_config_fails(LOCALHOST_WITH_REMOTE)
assert_config_fails(MULTIPLE_LOCAL_WITH_REMOTE)
assert_config_fails(JUST_WRONG_CONFIG)
node1.replace_config(
"/etc/clickhouse-server/config.d/enable_keeper1.xml", NORMAL_CONFIG
)
node1.start_clickhouse()
assert node1.query("SELECT 1") == "1\n"