ClickHouse/tests/integration/test_user_directories/test.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

176 lines
4.8 KiB
Python
Raw Normal View History

2020-08-12 23:26:40 +00:00
import os
import pytest
2020-08-12 23:26:40 +00:00
from helpers.cluster import ClickHouseCluster
from helpers.test_tools import TSV
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
cluster = ClickHouseCluster(__file__)
node = cluster.add_instance("node", stay_alive=True)
2020-08-12 23:26:40 +00:00
@pytest.fixture(scope="module", autouse=True)
def started_cluster():
try:
cluster.start()
for i in range(2, 8):
2021-06-02 15:08:16 +00:00
node.exec_in_container(
[
2021-06-02 15:08:16 +00:00
"cp",
"/etc/clickhouse-server/users.xml",
"/etc/clickhouse-server/users{}.xml".format(i),
]
2021-06-02 15:08:16 +00:00
)
2020-08-12 23:26:40 +00:00
yield cluster
finally:
cluster.shutdown()
def test_old_style():
node.copy_file_to_container(
os.path.join(SCRIPT_DIR, "configs/old_style.xml"),
"/etc/clickhouse-server/config.d/z.xml",
)
2020-08-12 23:26:40 +00:00
node.restart_clickhouse()
assert node.query("SELECT * FROM system.user_directories") == TSV(
[
[
"users_xml",
"users_xml",
'{"path":"\\\\/etc\\\\/clickhouse-server\\\\/users2.xml"}',
1,
],
[
"local_directory",
"local_directory",
'{"path":"\\\\/var\\\\/lib\\\\/clickhouse\\\\/access2\\\\/"}',
2,
],
]
)
2020-08-12 23:26:40 +00:00
def test_local_directories():
node.copy_file_to_container(
os.path.join(SCRIPT_DIR, "configs/local_directories.xml"),
"/etc/clickhouse-server/config.d/z.xml",
)
2020-08-12 23:26:40 +00:00
node.restart_clickhouse()
assert node.query("SELECT * FROM system.user_directories") == TSV(
[
[
"users_xml",
"users_xml",
'{"path":"\\\\/etc\\\\/clickhouse-server\\\\/users3.xml"}',
1,
],
[
"local_directory",
"local_directory",
'{"path":"\\\\/var\\\\/lib\\\\/clickhouse\\\\/access3\\\\/"}',
2,
],
[
"local directory (ro)",
"local_directory",
'{"path":"\\\\/var\\\\/lib\\\\/clickhouse\\\\/access3-ro\\\\/","readonly":true}',
3,
],
]
)
2020-08-12 23:26:40 +00:00
def test_relative_path():
node.copy_file_to_container(
os.path.join(SCRIPT_DIR, "configs/relative_path.xml"),
"/etc/clickhouse-server/config.d/z.xml",
)
2020-08-12 23:26:40 +00:00
node.restart_clickhouse()
assert node.query("SELECT * FROM system.user_directories") == TSV(
[
[
"users_xml",
"users_xml",
'{"path":"\\\\/etc\\\\/clickhouse-server\\\\/users4.xml"}',
1,
]
]
)
2020-08-12 23:26:40 +00:00
def test_memory():
node.copy_file_to_container(
os.path.join(SCRIPT_DIR, "configs/memory.xml"),
"/etc/clickhouse-server/config.d/z.xml",
)
node.restart_clickhouse()
assert node.query("SELECT * FROM system.user_directories") == TSV(
[
[
"users_xml",
"users_xml",
'{"path":"\\\\/etc\\\\/clickhouse-server\\\\/users5.xml"}',
1,
],
["memory", "memory", "{}", 2],
]
)
def test_mixed_style():
node.copy_file_to_container(
os.path.join(SCRIPT_DIR, "configs/mixed_style.xml"),
"/etc/clickhouse-server/config.d/z.xml",
)
node.restart_clickhouse()
assert node.query("SELECT * FROM system.user_directories") == TSV(
[
[
"users_xml",
"users_xml",
'{"path":"\\\\/etc\\\\/clickhouse-server\\\\/users6.xml"}',
1,
],
[
"local_directory",
"local_directory",
'{"path":"\\\\/var\\\\/lib\\\\/clickhouse\\\\/access6\\\\/"}',
2,
],
[
"local_directory",
"local_directory",
'{"path":"\\\\/var\\\\/lib\\\\/clickhouse\\\\/access6a\\\\/"}',
3,
],
["memory", "memory", "{}", 4],
]
)
def test_duplicates():
node.copy_file_to_container(
os.path.join(SCRIPT_DIR, "configs/duplicates.xml"),
"/etc/clickhouse-server/config.d/z.xml",
)
node.restart_clickhouse()
assert node.query("SELECT * FROM system.user_directories") == TSV(
[
[
"users_xml",
"users_xml",
'{"path":"\\\\/etc\\\\/clickhouse-server\\\\/users7.xml"}',
1,
],
[
"local_directory",
"local_directory",
'{"path":"\\\\/var\\\\/lib\\\\/clickhouse\\\\/access7\\\\/"}',
2,
],
]
)