[COMMIT scylla-cluster-tests master] refactor(integration-tests): use api object per test

0 views
Skip to first unread message

Commit Bot

<bot@cloudius-systems.com>
unread,
Jul 2, 2024, 2:02:26 AMJul 2
to scylladb-dev@googlegroups.com, Israel Fruchter
From: Israel Fruchter <fr...@scylladb.com>
Committer: Israel Fruchter <israel....@gmail.com>
Branch: master

refactor(integration-tests): use api object per test

since the alternator_api object was share across tests
it might cache `salted_hash` of other tests

need to refactor the code to make sure that doesn't happens

---
diff --git a/unit_tests/conftest.py b/unit_tests/conftest.py
--- a/unit_tests/conftest.py
+++ b/unit_tests/conftest.py
@@ -37,6 +37,7 @@
from unit_tests.lib.fake_provisioner import FakeProvisioner
from unit_tests.lib.fake_region_definition_builder import FakeDefinitionBuilder
from unit_tests.lib.fake_remoter import FakeRemoter
+from unit_tests.lib.alternator_utils import ALTERNATOR_PORT


@pytest.fixture(scope='module')
@@ -68,7 +69,7 @@ def fixture_docker_scylla(request: pytest.FixtureRequest, params): # pylint: di
entryfile_path = Path(base_dir) if base_dir else Path(__file__).parent.parent
entryfile_path = entryfile_path / 'docker' / 'scylla-sct' / ('entry_ssl.sh' if ssl else 'entry.sh')

- alternator_flags = "--alternator-port 8000 --alternator-write-isolation=always"
+ alternator_flags = f"--alternator-port {ALTERNATOR_PORT} --alternator-write-isolation=always"
docker_version = docker_scylla_args.get('image', "scylladb/scylla-nightly:6.1.0-dev-0.20240605.2c3f7c996f98")
cluster = LocalScyllaClusterDummy(params=params)

@@ -86,7 +87,7 @@ def fixture_docker_scylla(request: pytest.FixtureRequest, params): # pylint: di
finally:
os.chdir(curr_dir)
ssl_dir = (Path(__file__).parent.parent / 'data_dir' / 'ssl_conf').absolute()
- extra_docker_opts = (f'-p 8000 -p {BaseNode.CQL_PORT} --cpus="1" -v {entryfile_path}:/entry.sh'
+ extra_docker_opts = (f'-p {ALTERNATOR_PORT} -p {BaseNode.CQL_PORT} --cpus="1" -v {entryfile_path}:/entry.sh'
f' -v {ssl_dir}:{SCYLLA_SSL_CONF_DIR}'
' --entrypoint /entry.sh')

@@ -106,7 +107,7 @@ def db_up():

def db_alternator_up():
try:
- return scylla.is_port_used(port=8000, service_name="scylla-server")
+ return scylla.is_port_used(port=ALTERNATOR_PORT, service_name="scylla-server")
except Exception as details: # pylint: disable=broad-except # noqa: BLE001
logging.error("Error checking for scylla up normal: %s", details)
return False
diff --git a/unit_tests/lib/alternator_utils.py b/unit_tests/lib/alternator_utils.py
--- a/unit_tests/lib/alternator_utils.py
+++ b/unit_tests/lib/alternator_utils.py
@@ -13,19 +13,3 @@
from sdcm.utils import alternator

ALTERNATOR_PORT = 8000
-TEST_PARAMS = dict(
- dynamodb_primarykey_type="HASH_AND_RANGE",
- alternator_use_dns_routing=True,
- alternator_port=ALTERNATOR_PORT,
- alternator_enforce_authorization=True,
- alternator_access_key_id='alternator',
- alternator_secret_access_key='password',
- authenticator='PasswordAuthenticator',
- authenticator_user='cassandra',
- authenticator_password='cassandra',
- authorizer='CassandraAuthorizer',
- docker_network='ycsb_net',
-)
-ALTERNATOR = alternator.api.Alternator(
- sct_params=TEST_PARAMS
-)
diff --git a/unit_tests/test_alternator_streams_kcl.py b/unit_tests/test_alternator_streams_kcl.py
--- a/unit_tests/test_alternator_streams_kcl.py
+++ b/unit_tests/test_alternator_streams_kcl.py
@@ -18,7 +18,6 @@
from sdcm.ycsb_thread import YcsbStressThread
from sdcm.kcl_thread import KclStressThread, CompareTablesSizesThread
from unit_tests.dummy_remote import LocalLoaderSetDummy
-from unit_tests.lib.alternator_utils import TEST_PARAMS

pytestmark = [
pytest.mark.usefixtures("events"),
@@ -30,8 +29,16 @@
def test_01_kcl_with_ycsb(
request, docker_scylla, events, params
): # pylint: disable=too-many-locals
- params.update(TEST_PARAMS)
- loader_set = LocalLoaderSetDummy()
+ params.update(dict(
+ dynamodb_primarykey_type="HASH_AND_RANGE",
+ alternator_use_dns_routing=True,
+ alternator_port=ALTERNATOR_PORT,
+ alternator_enforce_authorization=True,
+ alternator_access_key_id='alternator',
+ alternator_secret_access_key='password',
+ docker_network='ycsb_net',
+ ))
+ loader_set = LocalLoaderSetDummy(params=params)
num_of_keys = 1000
# 1. start kcl thread and ycsb at the same time
ycsb_cmd = (
diff --git a/unit_tests/test_ycsb_thread.py b/unit_tests/test_ycsb_thread.py
--- a/unit_tests/test_ycsb_thread.py
+++ b/unit_tests/test_ycsb_thread.py
@@ -23,14 +23,43 @@
from sdcm.utils.docker_utils import running_in_docker
from sdcm.ycsb_thread import YcsbStressThread
from unit_tests.dummy_remote import LocalLoaderSetDummy
-from unit_tests.lib.alternator_utils import ALTERNATOR_PORT, ALTERNATOR, TEST_PARAMS
+from unit_tests.lib.alternator_utils import ALTERNATOR_PORT

pytestmark = [
pytest.mark.usefixtures("events"),
pytest.mark.integration,
]


+...@pytest.fixture(scope="function", name="alternator_api")
+def fixture_alternator_api(params):
+ params.update(dict(
+ dynamodb_primarykey_type="HASH_AND_RANGE",
+ alternator_use_dns_routing=True,
+ alternator_port=ALTERNATOR_PORT,
+ alternator_enforce_authorization=True,
+ alternator_access_key_id='alternator',
+ alternator_secret_access_key='password',
+ docker_network='ycsb_net',
+ ))
+
+ def create_endpoint_url(node):
+ if running_in_docker():
+ endpoint_url = f"http://{node.internal_ip_address}:{ALTERNATOR_PORT}"
+ else:
+ address = node.get_port(f"{ALTERNATOR_PORT}")
+ endpoint_url = f"http://{address}"
+ return endpoint_url
+
+ alternator_api = alternator.api.Alternator(
+ sct_params=params
+ )
+
+ alternator_api.create_endpoint_url = create_endpoint_url
+
+ return alternator_api
+
+
@pytest.fixture(scope="function", name="cql_driver")
def fixture_cql_driver(docker_scylla):
if running_in_docker():
@@ -44,25 +73,15 @@ def fixture_cql_driver(docker_scylla):


@pytest.fixture(scope="function")
-def create_table(docker_scylla, cql_driver):
+def create_table(docker_scylla, cql_driver, alternator_api, params):

with cql_driver.connect() as session:
session.execute("CREATE ROLE %s WITH PASSWORD = %s",
- (TEST_PARAMS.get('alternator_access_key_id'),
- TEST_PARAMS.get('alternator_secret_access_key')))
-
- def create_endpoint_url(node):
- if running_in_docker():
- endpoint_url = f"http://{node.internal_ip_address}:{ALTERNATOR_PORT}"
- else:
- address = node.get_port(f"{ALTERNATOR_PORT}")
- endpoint_url = f"http://{address}"
- return endpoint_url
+ (params.get('alternator_access_key_id'),
+ params.get('alternator_secret_access_key')))

setattr(docker_scylla, "name", "mock-node")
-
- ALTERNATOR.create_endpoint_url = create_endpoint_url
- ALTERNATOR.create_table(node=docker_scylla, table_name=alternator.consts.TABLE_NAME)
+ alternator_api.create_table(node=docker_scylla, table_name=alternator.consts.TABLE_NAME)


@pytest.fixture(scope="function")
@@ -91,7 +110,6 @@ def create_cql_ks_and_table(cql_driver):
@pytest.mark.usefixtures("create_table")
@pytest.mark.docker_scylla_args(docker_network='ycsb_net')
def test_01_dynamodb_api(request, docker_scylla, prom_address, params):
- params.update(TEST_PARAMS)
loader_set = LocalLoaderSetDummy(params=params)

cmd = (
@@ -134,7 +152,6 @@ def check_metrics():
def test_02_dynamodb_api_dataintegrity(
request, docker_scylla, prom_address, events, params
):
- params.update(TEST_PARAMS)
loader_set = LocalLoaderSetDummy(params=params)

# 2. do write without dataintegrity=true
@@ -197,7 +214,6 @@ def check_metrics():
@pytest.mark.usefixtures("create_cql_ks_and_table")
@pytest.mark.docker_scylla_args(docker_network='ycsb_net')
def test_03_cql(request, docker_scylla, prom_address, params):
- params.update(TEST_PARAMS)
loader_set = LocalLoaderSetDummy(params=params)

cmd = (
@@ -230,7 +246,7 @@ def check_metrics():


@pytest.mark.usefixtures("create_table")
-def test_04_insert_new_data(docker_scylla):
+def test_04_insert_new_data(docker_scylla, alternator_api):
schema = alternator.schemas.HASH_AND_STR_RANGE_SCHEMA
schema_keys = [key_details["AttributeName"] for key_details in schema["KeySchema"]]
new_items = [
@@ -246,11 +262,11 @@ def test_04_insert_new_data(docker_scylla):
{schema_keys[0]: "test_9", schema_keys[1]: "YrRvsqXAtppgCLiHhiQn"},
]

- ALTERNATOR.batch_write_actions(
+ alternator_api.batch_write_actions(
node=docker_scylla,
new_items=new_items,
schema=alternator.schemas.HASH_AND_STR_RANGE_SCHEMA,
)
- data = ALTERNATOR.scan_table(node=docker_scylla)
+ data = alternator_api.scan_table(node=docker_scylla)
assert {row[schema_keys[0]]: row[schema_keys[1]]
for row in new_items} == {row[schema_keys[0]]: row[schema_keys[1]] for row in data}
Reply all
Reply to author
Forward
0 new messages