test/cql-pytest: add tablet detection logic and fixtures

Add keyspace_has_tablets() utility function, which, given a keyspace,
returns whether it is using tablets or not.
In addition, 3 new fixtures are added:
* has_tablets - does scylla has tablets by default?
* xfail_tablets - the test is marked xfail, when tablets are enabled by
  default.
* skip_with_tablets - the test is skipped when tablets are enabled by
  default, because it might crash with tablets.

We expect the latter two to be removed soon(ish), as we make all test,
and the functionality they test work with tablets.
This commit is contained in:
Botond Dénes
2024-01-19 02:51:41 -05:00
parent 6e53264bc3
commit 2119faf7fe
2 changed files with 43 additions and 1 deletions

View File

@@ -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")

View File

@@ -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: