2020-03-18 14:12:09 +00:00
|
|
|
import pytest
|
2024-09-27 10:19:39 +00:00
|
|
|
|
2020-03-18 14:12:09 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
2020-05-12 20:31:30 +00:00
|
|
|
from helpers.test_tools import TSV
|
2020-03-18 14:12:09 +00:00
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
2024-09-16 09:57:20 +00:00
|
|
|
|
|
|
|
# `randomize_settings` is set tot `False` to maake result of `SHOW CREATE SETTINGS PROFILE` consistent
|
|
|
|
instance = cluster.add_instance("instance", randomize_settings=False)
|
2020-03-18 14:12:09 +00:00
|
|
|
|
|
|
|
|
2020-05-12 20:31:30 +00:00
|
|
|
def system_settings_profile(profile_name):
|
2020-09-16 04:26:10 +00:00
|
|
|
return TSV(
|
|
|
|
instance.query(
|
|
|
|
"SELECT name, storage, num_elements, apply_to_all, apply_to_list, apply_to_except FROM system.settings_profiles WHERE name='"
|
|
|
|
+ profile_name
|
|
|
|
+ "'"
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2020-05-12 20:31:30 +00:00
|
|
|
|
|
|
|
def system_settings_profile_elements(profile_name=None, user_name=None, role_name=None):
|
|
|
|
where = ""
|
|
|
|
if profile_name:
|
|
|
|
where = " WHERE profile_name='" + profile_name + "'"
|
|
|
|
elif user_name:
|
|
|
|
where = " WHERE user_name='" + user_name + "'"
|
|
|
|
elif role_name:
|
|
|
|
where = " WHERE role_name='" + role_name + "'"
|
|
|
|
return TSV(instance.query("SELECT * FROM system.settings_profile_elements" + where))
|
|
|
|
|
|
|
|
|
2021-07-22 16:07:03 +00:00
|
|
|
session_id_counter = 0
|
2022-03-22 16:39:58 +00:00
|
|
|
|
|
|
|
|
2021-07-22 16:07:03 +00:00
|
|
|
def new_session_id():
|
|
|
|
global session_id_counter
|
|
|
|
session_id_counter += 1
|
|
|
|
return "session #" + str(session_id_counter)
|
|
|
|
|
|
|
|
|
2020-03-18 14:12:09 +00:00
|
|
|
@pytest.fixture(scope="module", autouse=True)
|
|
|
|
def setup_nodes():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
|
|
|
instance.query("CREATE USER robin")
|
|
|
|
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def reset_after_test():
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
instance.query("CREATE USER OR REPLACE robin")
|
|
|
|
instance.query("DROP ROLE IF EXISTS worker")
|
2021-07-22 16:07:03 +00:00
|
|
|
instance.query(
|
|
|
|
"DROP SETTINGS PROFILE IF EXISTS xyz, alpha, P1, P2, P3, P4, P5, P6"
|
|
|
|
)
|
2020-03-18 14:12:09 +00:00
|
|
|
|
|
|
|
|
2020-05-12 20:31:30 +00:00
|
|
|
def test_smoke():
|
2021-02-14 01:34:42 +00:00
|
|
|
# Set settings and constraints via CREATE SETTINGS PROFILE ... TO user
|
2020-09-16 04:26:10 +00:00
|
|
|
instance.query(
|
|
|
|
"CREATE SETTINGS PROFILE xyz SETTINGS max_memory_usage = 100000001 MIN 90000000 MAX 110000000 TO robin"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
instance.query("SHOW CREATE SETTINGS PROFILE xyz")
|
2024-02-26 23:54:20 +00:00
|
|
|
== "CREATE SETTINGS PROFILE `xyz` SETTINGS max_memory_usage = 100000001 MIN 90000000 MAX 110000000 TO robin\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'max_memory_usage'",
|
|
|
|
user="robin",
|
|
|
|
)
|
|
|
|
== "100000001\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
"Setting max_memory_usage shouldn't be less than 90000000"
|
|
|
|
in instance.query_and_get_error("SET max_memory_usage = 80000000", user="robin")
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
"Setting max_memory_usage shouldn't be greater than 110000000"
|
|
|
|
in instance.query_and_get_error(
|
|
|
|
"SET max_memory_usage = 120000000", user="robin"
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert system_settings_profile("xyz") == [
|
2023-07-21 02:20:36 +00:00
|
|
|
["xyz", "local_directory", 1, 0, "['robin']", "[]"]
|
2022-03-22 16:39:58 +00:00
|
|
|
]
|
2020-09-16 04:26:10 +00:00
|
|
|
assert system_settings_profile_elements(profile_name="xyz") == [
|
2020-10-02 16:54:07 +00:00
|
|
|
[
|
|
|
|
"xyz",
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
|
|
|
0,
|
|
|
|
"max_memory_usage",
|
|
|
|
100000001,
|
|
|
|
90000000,
|
|
|
|
110000000,
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
|
|
|
]
|
2022-03-22 16:39:58 +00:00
|
|
|
]
|
2020-03-18 14:12:09 +00:00
|
|
|
|
|
|
|
instance.query("ALTER SETTINGS PROFILE xyz TO NONE")
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query("SHOW CREATE SETTINGS PROFILE xyz")
|
2024-02-26 23:54:20 +00:00
|
|
|
== "CREATE SETTINGS PROFILE `xyz` SETTINGS max_memory_usage = 100000001 MIN 90000000 MAX 110000000\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'max_memory_usage'",
|
|
|
|
user="robin",
|
|
|
|
)
|
2022-05-06 16:46:54 +00:00
|
|
|
== "0\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-03-18 14:12:09 +00:00
|
|
|
instance.query("SET max_memory_usage = 80000000", user="robin")
|
|
|
|
instance.query("SET max_memory_usage = 120000000", user="robin")
|
2020-09-16 04:26:10 +00:00
|
|
|
assert system_settings_profile("xyz") == [
|
2023-07-21 02:20:36 +00:00
|
|
|
["xyz", "local_directory", 1, 0, "[]", "[]"]
|
2022-03-22 16:39:58 +00:00
|
|
|
]
|
2020-05-12 20:31:30 +00:00
|
|
|
assert system_settings_profile_elements(user_name="robin") == []
|
2020-03-18 14:12:09 +00:00
|
|
|
|
|
|
|
# Set settings and constraints via CREATE USER ... SETTINGS PROFILE
|
|
|
|
instance.query("ALTER USER robin SETTINGS PROFILE xyz")
|
2020-04-07 23:57:14 +00:00
|
|
|
assert (
|
|
|
|
instance.query("SHOW CREATE USER robin")
|
2024-06-27 01:26:46 +00:00
|
|
|
== "CREATE USER robin IDENTIFIED WITH no_password SETTINGS PROFILE `xyz`\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'max_memory_usage'",
|
|
|
|
user="robin",
|
|
|
|
)
|
|
|
|
== "100000001\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
"Setting max_memory_usage shouldn't be less than 90000000"
|
|
|
|
in instance.query_and_get_error("SET max_memory_usage = 80000000", user="robin")
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
"Setting max_memory_usage shouldn't be greater than 110000000"
|
|
|
|
in instance.query_and_get_error(
|
|
|
|
"SET max_memory_usage = 120000000", user="robin"
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert system_settings_profile_elements(user_name="robin") == [
|
2022-09-15 11:34:14 +00:00
|
|
|
["\\N", "robin", "\\N", 0, "\\N", "\\N", "\\N", "\\N", "\\N", "xyz"]
|
2022-03-22 16:39:58 +00:00
|
|
|
]
|
2020-03-18 14:12:09 +00:00
|
|
|
|
|
|
|
instance.query("ALTER USER robin SETTINGS NONE")
|
2024-06-27 12:20:12 +00:00
|
|
|
assert (
|
|
|
|
instance.query("SHOW CREATE USER robin")
|
|
|
|
== "CREATE USER robin IDENTIFIED WITH no_password\n"
|
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'max_memory_usage'",
|
|
|
|
user="robin",
|
|
|
|
)
|
2022-05-06 16:46:54 +00:00
|
|
|
== "0\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-03-18 14:12:09 +00:00
|
|
|
instance.query("SET max_memory_usage = 80000000", user="robin")
|
|
|
|
instance.query("SET max_memory_usage = 120000000", user="robin")
|
2020-05-12 20:31:30 +00:00
|
|
|
assert system_settings_profile_elements(user_name="robin") == []
|
2020-03-18 14:12:09 +00:00
|
|
|
|
|
|
|
|
2020-05-12 20:31:30 +00:00
|
|
|
def test_settings_from_granted_role():
|
2020-03-18 14:12:09 +00:00
|
|
|
# Set settings and constraints via granted role
|
2020-09-16 04:26:10 +00:00
|
|
|
instance.query(
|
|
|
|
"CREATE SETTINGS PROFILE xyz SETTINGS max_memory_usage = 100000001 MAX 110000000, max_ast_depth = 2000"
|
|
|
|
)
|
2020-03-18 14:12:09 +00:00
|
|
|
instance.query("CREATE ROLE worker SETTINGS PROFILE xyz")
|
|
|
|
instance.query("GRANT worker TO robin")
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query("SHOW CREATE SETTINGS PROFILE xyz")
|
2024-02-26 23:54:20 +00:00
|
|
|
== "CREATE SETTINGS PROFILE `xyz` SETTINGS max_memory_usage = 100000001 MAX 110000000, max_ast_depth = 2000\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-04-07 23:57:14 +00:00
|
|
|
assert (
|
|
|
|
instance.query("SHOW CREATE ROLE worker")
|
2024-02-27 23:33:56 +00:00
|
|
|
== "CREATE ROLE worker SETTINGS PROFILE `xyz`\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'max_memory_usage'",
|
|
|
|
user="robin",
|
|
|
|
)
|
|
|
|
== "100000001\n"
|
2020-05-12 20:31:30 +00:00
|
|
|
)
|
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'max_ast_depth'",
|
|
|
|
user="robin",
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-05-12 20:31:30 +00:00
|
|
|
== "2000\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
"Setting max_memory_usage shouldn't be greater than 110000000"
|
|
|
|
in instance.query_and_get_error(
|
|
|
|
"SET max_memory_usage = 120000000", user="robin"
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert system_settings_profile("xyz") == [
|
2023-07-21 02:20:36 +00:00
|
|
|
["xyz", "local_directory", 2, 0, "[]", "[]"]
|
2022-03-22 16:39:58 +00:00
|
|
|
]
|
2020-09-16 04:26:10 +00:00
|
|
|
assert system_settings_profile_elements(profile_name="xyz") == [
|
2020-10-02 16:54:07 +00:00
|
|
|
[
|
|
|
|
"xyz",
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
|
|
|
0,
|
|
|
|
"max_memory_usage",
|
|
|
|
100000001,
|
|
|
|
"\\N",
|
|
|
|
110000000,
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
|
|
|
],
|
2022-09-08 15:52:00 +00:00
|
|
|
[
|
|
|
|
"xyz",
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
|
|
|
1,
|
|
|
|
"max_ast_depth",
|
|
|
|
2000,
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
|
|
|
],
|
2020-10-02 16:54:07 +00:00
|
|
|
]
|
2020-09-16 04:26:10 +00:00
|
|
|
assert system_settings_profile_elements(role_name="worker") == [
|
2022-09-15 11:34:14 +00:00
|
|
|
["\\N", "\\N", "worker", 0, "\\N", "\\N", "\\N", "\\N", "\\N", "xyz"]
|
2022-03-22 16:39:58 +00:00
|
|
|
]
|
2020-03-18 14:12:09 +00:00
|
|
|
|
|
|
|
instance.query("REVOKE worker FROM robin")
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'max_memory_usage'",
|
|
|
|
user="robin",
|
|
|
|
)
|
2022-05-06 16:46:54 +00:00
|
|
|
== "0\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-03-18 14:12:09 +00:00
|
|
|
instance.query("SET max_memory_usage = 120000000", user="robin")
|
|
|
|
|
|
|
|
instance.query("ALTER ROLE worker SETTINGS NONE")
|
|
|
|
instance.query("GRANT worker TO robin")
|
2020-04-07 23:57:14 +00:00
|
|
|
assert instance.query("SHOW CREATE ROLE worker") == "CREATE ROLE worker\n"
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'max_memory_usage'",
|
|
|
|
user="robin",
|
|
|
|
)
|
2022-05-06 16:46:54 +00:00
|
|
|
== "0\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-03-18 14:12:09 +00:00
|
|
|
instance.query("SET max_memory_usage = 120000000", user="robin")
|
2020-05-12 20:31:30 +00:00
|
|
|
assert system_settings_profile_elements(role_name="worker") == []
|
2020-03-18 14:12:09 +00:00
|
|
|
|
|
|
|
# Set settings and constraints via CREATE SETTINGS PROFILE ... TO granted role
|
|
|
|
instance.query("ALTER SETTINGS PROFILE xyz TO worker")
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query("SHOW CREATE SETTINGS PROFILE xyz")
|
2024-02-26 23:54:20 +00:00
|
|
|
== "CREATE SETTINGS PROFILE `xyz` SETTINGS max_memory_usage = 100000001 MAX 110000000, max_ast_depth = 2000 TO worker\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'max_memory_usage'",
|
|
|
|
user="robin",
|
|
|
|
)
|
|
|
|
== "100000001\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
"Setting max_memory_usage shouldn't be greater than 110000000"
|
|
|
|
in instance.query_and_get_error(
|
|
|
|
"SET max_memory_usage = 120000000", user="robin"
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert system_settings_profile("xyz") == [
|
2023-07-21 02:20:36 +00:00
|
|
|
["xyz", "local_directory", 2, 0, "['worker']", "[]"]
|
2022-03-22 16:39:58 +00:00
|
|
|
]
|
2020-03-18 14:12:09 +00:00
|
|
|
|
|
|
|
instance.query("ALTER SETTINGS PROFILE xyz TO NONE")
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query("SHOW CREATE SETTINGS PROFILE xyz")
|
2024-02-26 23:54:20 +00:00
|
|
|
== "CREATE SETTINGS PROFILE `xyz` SETTINGS max_memory_usage = 100000001 MAX 110000000, max_ast_depth = 2000\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'max_memory_usage'",
|
|
|
|
user="robin",
|
|
|
|
)
|
2022-05-06 16:46:54 +00:00
|
|
|
== "0\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-03-18 14:12:09 +00:00
|
|
|
instance.query("SET max_memory_usage = 120000000", user="robin")
|
2020-09-16 04:26:10 +00:00
|
|
|
assert system_settings_profile("xyz") == [
|
2023-07-21 02:20:36 +00:00
|
|
|
["xyz", "local_directory", 2, 0, "[]", "[]"]
|
2022-03-22 16:39:58 +00:00
|
|
|
]
|
2020-03-18 14:12:09 +00:00
|
|
|
|
|
|
|
|
2020-05-12 20:31:30 +00:00
|
|
|
def test_inheritance():
|
2020-03-18 14:12:09 +00:00
|
|
|
instance.query(
|
2022-09-15 11:34:14 +00:00
|
|
|
"CREATE SETTINGS PROFILE xyz SETTINGS max_memory_usage = 100000002 CONST"
|
2020-03-18 14:12:09 +00:00
|
|
|
)
|
|
|
|
instance.query("CREATE SETTINGS PROFILE alpha SETTINGS PROFILE xyz TO robin")
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query("SHOW CREATE SETTINGS PROFILE xyz")
|
2024-02-26 23:54:20 +00:00
|
|
|
== "CREATE SETTINGS PROFILE `xyz` SETTINGS max_memory_usage = 100000002 CONST\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query("SHOW CREATE SETTINGS PROFILE alpha")
|
2024-02-27 16:41:30 +00:00
|
|
|
== "CREATE SETTINGS PROFILE `alpha` SETTINGS INHERIT `xyz` TO robin\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'max_memory_usage'",
|
|
|
|
user="robin",
|
|
|
|
)
|
|
|
|
== "100000002\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
"Setting max_memory_usage should not be changed"
|
|
|
|
in instance.query_and_get_error("SET max_memory_usage = 80000000", user="robin")
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
assert system_settings_profile("xyz") == [
|
2023-07-21 02:20:36 +00:00
|
|
|
["xyz", "local_directory", 1, 0, "[]", "[]"]
|
2022-03-22 16:39:58 +00:00
|
|
|
]
|
2020-09-16 04:26:10 +00:00
|
|
|
assert system_settings_profile_elements(profile_name="xyz") == [
|
2022-09-08 15:52:00 +00:00
|
|
|
[
|
|
|
|
"xyz",
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
|
|
|
0,
|
|
|
|
"max_memory_usage",
|
|
|
|
100000002,
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
2022-09-15 11:34:14 +00:00
|
|
|
"CONST",
|
2022-09-08 15:52:00 +00:00
|
|
|
"\\N",
|
|
|
|
]
|
2022-03-22 16:39:58 +00:00
|
|
|
]
|
2020-09-16 04:26:10 +00:00
|
|
|
assert system_settings_profile("alpha") == [
|
2023-07-21 02:20:36 +00:00
|
|
|
["alpha", "local_directory", 1, 0, "['robin']", "[]"]
|
2022-03-22 16:39:58 +00:00
|
|
|
]
|
2020-09-16 04:26:10 +00:00
|
|
|
assert system_settings_profile_elements(profile_name="alpha") == [
|
2022-09-15 11:34:14 +00:00
|
|
|
["alpha", "\\N", "\\N", 0, "\\N", "\\N", "\\N", "\\N", "\\N", "xyz"]
|
2022-03-22 16:39:58 +00:00
|
|
|
]
|
2020-05-12 20:31:30 +00:00
|
|
|
assert system_settings_profile_elements(user_name="robin") == []
|
|
|
|
|
2020-03-18 14:12:09 +00:00
|
|
|
|
|
|
|
def test_alter_and_drop():
|
2020-09-16 04:26:10 +00:00
|
|
|
instance.query(
|
|
|
|
"CREATE SETTINGS PROFILE xyz SETTINGS max_memory_usage = 100000003 MIN 90000000 MAX 110000000 TO robin"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'max_memory_usage'",
|
|
|
|
user="robin",
|
|
|
|
)
|
|
|
|
== "100000003\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
"Setting max_memory_usage shouldn't be less than 90000000"
|
|
|
|
in instance.query_and_get_error("SET max_memory_usage = 80000000", user="robin")
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
"Setting max_memory_usage shouldn't be greater than 110000000"
|
|
|
|
in instance.query_and_get_error(
|
|
|
|
"SET max_memory_usage = 120000000", user="robin"
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-03-18 14:12:09 +00:00
|
|
|
|
|
|
|
instance.query("ALTER SETTINGS PROFILE xyz SETTINGS readonly=1")
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
"Cannot modify 'max_memory_usage' setting in readonly mode"
|
|
|
|
in instance.query_and_get_error("SET max_memory_usage = 80000000", user="robin")
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-03-18 14:12:09 +00:00
|
|
|
|
|
|
|
instance.query("DROP SETTINGS PROFILE xyz")
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'max_memory_usage'",
|
|
|
|
user="robin",
|
|
|
|
)
|
2022-05-06 16:46:54 +00:00
|
|
|
== "0\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-03-18 14:12:09 +00:00
|
|
|
instance.query("SET max_memory_usage = 80000000", user="robin")
|
|
|
|
instance.query("SET max_memory_usage = 120000000", user="robin")
|
2020-03-24 08:01:50 +00:00
|
|
|
|
|
|
|
|
2022-09-09 12:01:11 +00:00
|
|
|
def test_changeable_in_readonly():
|
|
|
|
instance.query(
|
|
|
|
"CREATE SETTINGS PROFILE xyz SETTINGS max_memory_usage = 100000003 MIN 90000000 MAX 110000000 CHANGEABLE_IN_READONLY SETTINGS readonly = 1 TO robin"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'max_memory_usage'",
|
|
|
|
user="robin",
|
|
|
|
)
|
|
|
|
== "100000003\n"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT value FROM system.settings WHERE name = 'readonly'",
|
|
|
|
user="robin",
|
|
|
|
)
|
|
|
|
== "1\n"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
"Setting max_memory_usage shouldn't be less than 90000000"
|
|
|
|
in instance.query_and_get_error("SET max_memory_usage = 80000000", user="robin")
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
"Setting max_memory_usage shouldn't be greater than 110000000"
|
|
|
|
in instance.query_and_get_error(
|
|
|
|
"SET max_memory_usage = 120000000", user="robin"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
assert system_settings_profile_elements(profile_name="xyz") == [
|
|
|
|
[
|
|
|
|
"xyz",
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
|
|
|
0,
|
|
|
|
"max_memory_usage",
|
|
|
|
100000003,
|
|
|
|
90000000,
|
|
|
|
110000000,
|
2022-09-15 11:34:14 +00:00
|
|
|
"CHANGEABLE_IN_READONLY",
|
2022-09-09 12:01:11 +00:00
|
|
|
"\\N",
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"xyz",
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
|
|
|
1,
|
|
|
|
"readonly",
|
|
|
|
1,
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
|
|
|
"\\N",
|
2022-09-09 12:27:13 +00:00
|
|
|
],
|
2022-09-09 12:01:11 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
instance.query("SET max_memory_usage = 90000000", user="robin")
|
|
|
|
instance.query("SET max_memory_usage = 110000000", user="robin")
|
|
|
|
|
|
|
|
|
2020-05-12 20:31:30 +00:00
|
|
|
def test_show_profiles():
|
|
|
|
instance.query("CREATE SETTINGS PROFILE xyz")
|
|
|
|
assert instance.query("SHOW SETTINGS PROFILES") == "default\nreadonly\nxyz\n"
|
|
|
|
assert instance.query("SHOW PROFILES") == "default\nreadonly\nxyz\n"
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2024-02-27 00:01:34 +00:00
|
|
|
assert (
|
|
|
|
instance.query("SHOW CREATE PROFILE xyz") == "CREATE SETTINGS PROFILE `xyz`\n"
|
|
|
|
)
|
2024-02-14 09:50:55 +00:00
|
|
|
|
|
|
|
query_possible_response = [
|
2024-02-27 16:41:30 +00:00
|
|
|
"CREATE SETTINGS PROFILE `default`\n",
|
2024-07-12 12:49:26 +00:00
|
|
|
"CREATE SETTINGS PROFILE `default` SETTINGS enable_analyzer = true\n",
|
2024-02-14 09:50:55 +00:00
|
|
|
]
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
2021-02-14 01:34:42 +00:00
|
|
|
instance.query("SHOW CREATE SETTINGS PROFILE default")
|
2024-02-14 09:50:55 +00:00
|
|
|
in query_possible_response
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2024-02-14 09:50:55 +00:00
|
|
|
|
|
|
|
query_possible_response = [
|
2024-02-26 23:54:20 +00:00
|
|
|
"CREATE SETTINGS PROFILE `default`\n"
|
|
|
|
"CREATE SETTINGS PROFILE `readonly` SETTINGS readonly = 1\n"
|
|
|
|
"CREATE SETTINGS PROFILE `xyz`\n",
|
2024-07-12 12:49:26 +00:00
|
|
|
"CREATE SETTINGS PROFILE `default` SETTINGS enable_analyzer = true\n"
|
2024-02-26 23:54:20 +00:00
|
|
|
"CREATE SETTINGS PROFILE `readonly` SETTINGS readonly = 1\n"
|
|
|
|
"CREATE SETTINGS PROFILE `xyz`\n",
|
2024-02-14 09:50:55 +00:00
|
|
|
]
|
|
|
|
assert instance.query("SHOW CREATE PROFILES") in query_possible_response
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2021-02-14 01:34:42 +00:00
|
|
|
expected_access = (
|
2024-02-26 23:54:20 +00:00
|
|
|
"CREATE SETTINGS PROFILE `default`\n"
|
|
|
|
"CREATE SETTINGS PROFILE `readonly` SETTINGS readonly = 1\n"
|
|
|
|
"CREATE SETTINGS PROFILE `xyz`\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2024-02-14 09:50:55 +00:00
|
|
|
expected_access_analyzer = (
|
2024-07-12 12:49:26 +00:00
|
|
|
"CREATE SETTINGS PROFILE `default` SETTINGS enable_analyzer = true\n"
|
2024-02-26 23:54:20 +00:00
|
|
|
"CREATE SETTINGS PROFILE `readonly` SETTINGS readonly = 1\n"
|
|
|
|
"CREATE SETTINGS PROFILE `xyz`\n"
|
2024-02-14 09:50:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
query_response = instance.query("SHOW ACCESS")
|
|
|
|
assert (
|
|
|
|
expected_access in query_response or expected_access_analyzer in query_response
|
|
|
|
)
|
2020-05-12 20:31:30 +00:00
|
|
|
|
|
|
|
|
2021-07-22 16:07:03 +00:00
|
|
|
def test_set_profile():
|
2021-07-23 06:15:26 +00:00
|
|
|
instance.query(
|
|
|
|
"CREATE SETTINGS PROFILE P1 SETTINGS max_memory_usage=10000000001 MAX 20000000002"
|
|
|
|
)
|
2021-07-22 16:07:03 +00:00
|
|
|
|
|
|
|
session_id = new_session_id()
|
|
|
|
instance.http_query(
|
|
|
|
"SET profile='P1'", user="robin", params={"session_id": session_id}
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
instance.http_query(
|
|
|
|
"SELECT getSetting('max_memory_usage')",
|
|
|
|
user="robin",
|
|
|
|
params={"session_id": session_id},
|
|
|
|
)
|
|
|
|
== "10000000001\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-07-22 16:07:03 +00:00
|
|
|
|
2021-07-23 06:15:26 +00:00
|
|
|
expected_error = "max_memory_usage shouldn't be greater than 20000000002"
|
|
|
|
assert expected_error in instance.http_query_and_get_error(
|
|
|
|
"SET max_memory_usage=20000000003",
|
|
|
|
user="robin",
|
|
|
|
params={"session_id": session_id},
|
|
|
|
)
|
|
|
|
|
2021-07-22 16:07:03 +00:00
|
|
|
|
|
|
|
def test_changing_default_profiles_affects_new_sessions_only():
|
|
|
|
instance.query("CREATE SETTINGS PROFILE P1 SETTINGS max_memory_usage=10000000001")
|
|
|
|
instance.query("CREATE SETTINGS PROFILE P2 SETTINGS max_memory_usage=10000000002")
|
|
|
|
instance.query("ALTER USER robin SETTINGS PROFILE P1")
|
|
|
|
|
|
|
|
session_id = new_session_id()
|
|
|
|
assert (
|
|
|
|
instance.http_query(
|
|
|
|
"SELECT getSetting('max_memory_usage')",
|
|
|
|
user="robin",
|
|
|
|
params={"session_id": session_id},
|
|
|
|
)
|
|
|
|
== "10000000001\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-07-22 16:07:03 +00:00
|
|
|
instance.query("ALTER USER robin SETTINGS PROFILE P2")
|
|
|
|
assert (
|
|
|
|
instance.http_query(
|
|
|
|
"SELECT getSetting('max_memory_usage')",
|
|
|
|
user="robin",
|
|
|
|
params={"session_id": session_id},
|
|
|
|
)
|
|
|
|
== "10000000001\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-07-22 16:07:03 +00:00
|
|
|
|
|
|
|
other_session_id = new_session_id()
|
|
|
|
assert (
|
|
|
|
instance.http_query(
|
|
|
|
"SELECT getSetting('max_memory_usage')",
|
|
|
|
user="robin",
|
|
|
|
params={"session_id": other_session_id},
|
|
|
|
)
|
|
|
|
== "10000000002\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-07-22 16:07:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_function_current_profiles():
|
|
|
|
instance.query("CREATE SETTINGS PROFILE P1, P2")
|
|
|
|
instance.query("ALTER USER robin SETTINGS PROFILE P1, P2")
|
|
|
|
instance.query("CREATE SETTINGS PROFILE P3 TO robin")
|
|
|
|
instance.query("CREATE SETTINGS PROFILE P4")
|
|
|
|
instance.query("CREATE SETTINGS PROFILE P5 SETTINGS INHERIT P4")
|
|
|
|
instance.query("CREATE ROLE worker SETTINGS PROFILE P5")
|
|
|
|
instance.query("GRANT worker TO robin")
|
|
|
|
instance.query("CREATE SETTINGS PROFILE P6")
|
|
|
|
|
|
|
|
session_id = new_session_id()
|
|
|
|
assert (
|
|
|
|
instance.http_query(
|
|
|
|
"SELECT defaultProfiles(), currentProfiles(), enabledProfiles()",
|
|
|
|
user="robin",
|
|
|
|
params={"session_id": session_id},
|
|
|
|
)
|
2022-11-29 22:32:27 +00:00
|
|
|
== "['P1','P2']\t['default','P3','P5','P1','P2']\t['default','P3','P4','P5','P1','P2']\n"
|
2021-07-22 16:07:03 +00:00
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2021-07-22 16:07:03 +00:00
|
|
|
instance.http_query(
|
|
|
|
"SET profile='P6'", user="robin", params={"session_id": session_id}
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
instance.http_query(
|
|
|
|
"SELECT defaultProfiles(), currentProfiles(), enabledProfiles()",
|
|
|
|
user="robin",
|
|
|
|
params={"session_id": session_id},
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-07-22 16:07:03 +00:00
|
|
|
== "['P1','P2']\t['P6']\t['default','P3','P4','P5','P1','P2','P6']\n"
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2021-07-22 16:07:03 +00:00
|
|
|
instance.http_query(
|
|
|
|
"SET profile='P5'", user="robin", params={"session_id": session_id}
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
instance.http_query(
|
|
|
|
"SELECT defaultProfiles(), currentProfiles(), enabledProfiles()",
|
|
|
|
user="robin",
|
|
|
|
params={"session_id": session_id},
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-07-22 16:07:03 +00:00
|
|
|
== "['P1','P2']\t['P5']\t['default','P3','P1','P2','P6','P4','P5']\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-07-22 16:07:03 +00:00
|
|
|
|
|
|
|
instance.query("ALTER USER robin SETTINGS PROFILE P2")
|
|
|
|
assert (
|
|
|
|
instance.http_query(
|
|
|
|
"SELECT defaultProfiles(), currentProfiles(), enabledProfiles()",
|
|
|
|
user="robin",
|
|
|
|
params={"session_id": session_id},
|
|
|
|
)
|
|
|
|
== "['P2']\t['P5']\t['default','P3','P1','P2','P6','P4','P5']\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-07-22 16:07:03 +00:00
|
|
|
|
|
|
|
|
2020-06-28 18:42:03 +00:00
|
|
|
def test_allow_ddl():
|
2023-08-06 12:48:20 +00:00
|
|
|
assert "it's necessary to have the grant" in instance.query_and_get_error(
|
2020-12-08 18:09:13 +00:00
|
|
|
"CREATE TABLE tbl(a Int32) ENGINE=Log", user="robin"
|
|
|
|
)
|
2023-08-06 12:48:20 +00:00
|
|
|
assert "it's necessary to have the grant" in instance.query_and_get_error(
|
2020-12-08 18:09:13 +00:00
|
|
|
"GRANT CREATE ON tbl TO robin", user="robin"
|
|
|
|
)
|
|
|
|
assert "DDL queries are prohibited" in instance.query_and_get_error(
|
|
|
|
"CREATE TABLE tbl(a Int32) ENGINE=Log", settings={"allow_ddl": 0}
|
|
|
|
)
|
2021-02-14 01:34:42 +00:00
|
|
|
|
2020-06-28 18:42:03 +00:00
|
|
|
instance.query("GRANT CREATE ON tbl TO robin")
|
2024-03-16 22:18:42 +00:00
|
|
|
instance.query("GRANT TABLE ENGINE ON Log TO robin")
|
2020-06-28 18:42:03 +00:00
|
|
|
instance.query("CREATE TABLE tbl(a Int32) ENGINE=Log", user="robin")
|
|
|
|
instance.query("DROP TABLE tbl")
|
|
|
|
|
|
|
|
|
2020-03-24 08:01:50 +00:00
|
|
|
def test_allow_introspection():
|
2020-09-16 04:26:10 +00:00
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT demangle('a')", settings={"allow_introspection_functions": 1}
|
|
|
|
)
|
|
|
|
== "signed char\n"
|
2020-12-08 18:07:50 +00:00
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2020-12-08 18:07:50 +00:00
|
|
|
assert "Introspection functions are disabled" in instance.query_and_get_error(
|
|
|
|
"SELECT demangle('a')"
|
|
|
|
)
|
2023-08-06 12:48:20 +00:00
|
|
|
assert "it's necessary to have the grant" in instance.query_and_get_error(
|
2020-12-08 18:07:50 +00:00
|
|
|
"SELECT demangle('a')", user="robin"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2023-08-06 12:48:20 +00:00
|
|
|
assert "it's necessary to have the grant" in instance.query_and_get_error(
|
2020-12-08 18:07:50 +00:00
|
|
|
"SELECT demangle('a')",
|
|
|
|
user="robin",
|
|
|
|
settings={"allow_introspection_functions": 1},
|
|
|
|
)
|
|
|
|
|
|
|
|
instance.query("GRANT demangle ON *.* TO robin")
|
2020-06-28 18:41:41 +00:00
|
|
|
assert "Introspection functions are disabled" in instance.query_and_get_error(
|
2020-12-08 18:07:50 +00:00
|
|
|
"SELECT demangle('a')", user="robin"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
instance.query(
|
|
|
|
"SELECT demangle('a')",
|
|
|
|
user="robin",
|
|
|
|
settings={"allow_introspection_functions": 1},
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-12-08 18:07:50 +00:00
|
|
|
== "signed char\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-12-08 18:07:50 +00:00
|
|
|
|
2020-03-24 08:01:50 +00:00
|
|
|
instance.query("ALTER USER robin SETTINGS allow_introspection_functions=1")
|
|
|
|
assert instance.query("SELECT demangle('a')", user="robin") == "signed char\n"
|
|
|
|
|
|
|
|
instance.query("ALTER USER robin SETTINGS NONE")
|
|
|
|
assert "Introspection functions are disabled" in instance.query_and_get_error(
|
|
|
|
"SELECT demangle('a')", user="robin"
|
|
|
|
)
|
|
|
|
|
|
|
|
instance.query(
|
|
|
|
"CREATE SETTINGS PROFILE xyz SETTINGS allow_introspection_functions=1 TO robin"
|
|
|
|
)
|
|
|
|
assert instance.query("SELECT demangle('a')", user="robin") == "signed char\n"
|
|
|
|
|
|
|
|
instance.query("DROP SETTINGS PROFILE xyz")
|
|
|
|
assert "Introspection functions are disabled" in instance.query_and_get_error(
|
|
|
|
"SELECT demangle('a')", user="robin"
|
|
|
|
)
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
instance.query(
|
|
|
|
"REVOKE demangle ON *.* FROM robin",
|
|
|
|
settings={"allow_introspection_functions": 1},
|
2020-12-08 18:07:50 +00:00
|
|
|
)
|
2023-08-06 12:48:20 +00:00
|
|
|
assert "it's necessary to have the grant" in instance.query_and_get_error(
|
2020-12-08 18:07:50 +00:00
|
|
|
"SELECT demangle('a')", user="robin"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2023-01-27 09:39:10 +00:00
|
|
|
|
2023-01-27 09:46:51 +00:00
|
|
|
|
2023-01-27 09:39:10 +00:00
|
|
|
def test_settings_aliases():
|
2023-01-27 09:46:51 +00:00
|
|
|
instance.query(
|
|
|
|
"CREATE SETTINGS PROFILE P1 SETTINGS replication_alter_partitions_sync=2"
|
|
|
|
)
|
|
|
|
instance.query(
|
|
|
|
"CREATE SETTINGS PROFILE P2 SETTINGS replication_alter_partitions_sync=0"
|
|
|
|
)
|
2023-01-27 09:39:10 +00:00
|
|
|
instance.query("ALTER USER robin SETTINGS PROFILE P1")
|
|
|
|
|
|
|
|
assert (
|
|
|
|
instance.http_query(
|
|
|
|
"SELECT getSetting('alter_sync')",
|
|
|
|
user="robin",
|
|
|
|
)
|
|
|
|
== "2\n"
|
|
|
|
)
|
|
|
|
|
|
|
|
instance.query("ALTER USER robin SETTINGS PROFILE P2")
|
|
|
|
|
|
|
|
assert (
|
|
|
|
instance.http_query(
|
|
|
|
"SELECT getSetting('alter_sync')",
|
|
|
|
user="robin",
|
|
|
|
)
|
|
|
|
== "0\n"
|
|
|
|
)
|