diff --git a/test/cluster/test_guardrails.py b/test/cluster/test_guardrails.py index a2487e3f1a..e650ba4f60 100644 --- a/test/cluster/test_guardrails.py +++ b/test/cluster/test_guardrails.py @@ -5,13 +5,17 @@ # import logging - import pytest +import time + +from cassandra import ConsistencyLevel from cassandra.protocol import ConfigurationException, InvalidRequest +from cassandra.query import SimpleStatement from test.pylib.async_cql import _wrap_future -from test.pylib.manager_client import ManagerClient +from test.pylib.manager_client import ManagerClient, wait_for_cql_and_get_hosts from test.pylib.util import unique_name +from test.cluster.util import new_test_keyspace logger = logging.getLogger(__name__) @@ -97,3 +101,48 @@ async def test_all_rf_limits(manager: ManagerClient): await create_ks_and_assert_warning(cql, query, ks_name, ["warn", "max", "replication", "factor", str(MAX_WARN_THRESHOLD), dc, str(rf)]) else: await create_ks_and_assert_warning(cql, query, ks_name, []) + + +@pytest.mark.asyncio +async def test_invalid_write_cl_guardrail_config(manager: ManagerClient): + """A node configured with invalid values for write_consistency_levels_warned + and write_consistency_levels_disallowed should still start and respond to + CQL queries. The invalid values cause yaml-cpp conversion errors logged + during startup.""" + cfg = { + "write_consistency_levels_warned": ["INVALID_CL", "BOGUS"], + "write_consistency_levels_disallowed": ["NOT_A_CL"], + } + manager.ignore_log_patterns.append("bad conversion : write_consistency_levels_warned") + manager.ignore_log_patterns.append("bad conversion : write_consistency_levels_disallowed") + + server = await manager.server_add(config=cfg) + log = await manager.server_open_log(server.server_id) + + assert len(await log.grep("bad conversion : write_consistency_levels_warned")) > 0 + assert len(await log.grep("bad conversion : write_consistency_levels_disallowed")) > 0 + + cql, _ = await manager.get_ready_cql([server]) + rows = await cql.run_async("SELECT * FROM system.local") + assert len(rows) == 1 + +@pytest.mark.asyncio +async def test_write_cl_default(manager: ManagerClient): + """Test checks that the current implementation doesn't cause + any warning nor failure for the default configuration.""" + + servers = await manager.servers_add(3, auto_rack_dc="dc1") + cql, _ = await manager.get_ready_cql(servers) + + async with new_test_keyspace(manager, "WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 3}") as ks: + await cql.run_async(f"CREATE TABLE {ks}.t (pk int PRIMARY KEY, v int)") + + all_cls = [ConsistencyLevel.ANY, ConsistencyLevel.ONE, ConsistencyLevel.LOCAL_ONE, + ConsistencyLevel.TWO, ConsistencyLevel.THREE, ConsistencyLevel.QUORUM, + ConsistencyLevel.ALL, ConsistencyLevel.LOCAL_QUORUM, ConsistencyLevel.EACH_QUORUM] + + for cl in all_cls: + stmt = SimpleStatement(f"INSERT INTO {ks}.t (pk, v) VALUES (1, 1)", consistency_level=cl) + ret = cql.execute_async(stmt) + await _wrap_future(ret) + assert not ret.warnings, f"Expected no warning for {ConsistencyLevel.value_to_name[cl]}, got {ret.warnings}"