diff --git a/test/cql-pytest/conftest.py b/test/cql-pytest/conftest.py index a71868409c..0b0c72bc24 100644 --- a/test/cql-pytest/conftest.py +++ b/test/cql-pytest/conftest.py @@ -21,7 +21,7 @@ import tempfile import time import random -from util import unique_name, new_test_table, cql_session, local_process_id, is_scylla +from util import unique_name, new_test_keyspace, keyspace_has_tablets, cql_session, local_process_id, is_scylla print(f"Driver name {DRIVER_NAME}, version {DRIVER_VERSION}") @@ -220,3 +220,18 @@ def temp_workdir(): """ Creates a temporary work directory, for the scope of a single test. """ with tempfile.TemporaryDirectory() as workdir: yield workdir + +@pytest.fixture(scope="session") +def has_tablets(cql): + with new_test_keyspace(cql, " WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor': 1}") as keyspace: + return keyspace_has_tablets(cql, keyspace) + +@pytest.fixture(scope="function") +def xfail_tablets(request, has_tablets): + if has_tablets: + request.node.add_marker(pytest.mark.xfail(reason='Test expected to fail with tablets experimental feature on')) + +@pytest.fixture(scope="function") +def skip_with_tablets(has_tablets): + if has_tablets: + pytest.skip("Test may crash with tablets experimental feature on") diff --git a/test/cql-pytest/util.py b/test/cql-pytest/util.py index 8de31aa9ca..b35883ad66 100644 --- a/test/cql-pytest/util.py +++ b/test/cql-pytest/util.py @@ -70,6 +70,33 @@ def is_scylla(cql): names = [row.table_name for row in cql.execute("SELECT * FROM system_schema.tables WHERE keyspace_name = 'system'")] return any('scylla' in name for name in names) +def keyspace_has_tablets(cql, keyspace): + """ Return true if the keyspace was created with tablets. + + We support running cql-pytest against an older version of scylla, so we do + the detection in a way that accounts for scylla possibly not even knowing + what tablets is. + For cassandra, this will always return no. + + If the keyspace was created with tablets, it will have an entry in + `system_schema.scylla_keyspaces`, with `initial_tablets` set. + So here, we simply query this table, looking for a partition for the + appropriate keyspace. If the result has the `initial_tablets` column and it + is set, the keyspace has tablets. + """ + if not is_scylla(cql): + return False + + # Need to use network strategy, otherwise tablets will not be enabled. + res = list(cql.execute(f"SELECT * FROM system_schema.scylla_keyspaces WHERE keyspace_name='{keyspace}'")) + # The row migh exist due to storage related options, but the tablets related fields are null. + # So we check that: + # * the row exists + # * `initial_tablets` has a value + if not res: + return False + return getattr(res[0], "initial_tablets", None) is not None + # A utility function for creating a new temporary keyspace with given options. # It can be used in a "with", as: # with new_test_keyspace(cql, '...') as keyspace: