diff options
author | ijon <ijon@ydb.tech> | 2025-04-01 14:55:02 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-01 14:55:02 +0300 |
commit | 2d25d332aa8123ebd45a1e868811687c25ad097c (patch) | |
tree | 175328ed960fd51a7a3c8f625898fbc5770458de | |
parent | a1278fe78caf7b05a927f9802e2b267b51c2b1c4 (diff) | |
download | ydb-2d25d332aa8123ebd45a1e868811687c25ad097c.tar.gz |
tests/library: cleanup leftovers (#16591)
Remove accidental litter remaining after separating fixtures from library/harness.
-rw-r--r-- | ydb/tests/library/fixtures/__init__.py_ | 168 |
1 files changed, 0 insertions, 168 deletions
diff --git a/ydb/tests/library/fixtures/__init__.py_ b/ydb/tests/library/fixtures/__init__.py_ deleted file mode 100644 index 0e4ecceffc..0000000000 --- a/ydb/tests/library/fixtures/__init__.py_ +++ /dev/null @@ -1,168 +0,0 @@ -# -*- coding: utf-8 -*- -import contextlib -import logging -import os - -import pytest - -from ydb import Driver, DriverConfig, SessionPool - -from ydb.tests.library.common.types import Erasure -from ydb.tests.library.harness.kikimr_runner import KiKiMR -from ydb.tests.library.harness.kikimr_config import KikimrConfigGenerator -from ydb.tests.library.harness.util import LogLevels - -logger = logging.getLogger(__name__) - - -DEFAULT_CLUSTER_CONFIG = dict( - erasure=Erasure.NONE, - nodes=1, - additional_log_configs={ - 'FLAT_TX_SCHEMESHARD': LogLevels.DEBUG, - 'SCHEME_BOARD_POPULATOR': LogLevels.WARN, - 'SCHEME_BOARD_SUBSCRIBER': LogLevels.WARN, - 'TX_DATASHARD': LogLevels.DEBUG, - 'CHANGE_EXCHANGE': LogLevels.DEBUG, - }, -) - - -@pytest.fixture(scope='module') -def ydb_cluster_configuration(request): - conf = getattr(request.module, 'CLUSTER_CONFIG', DEFAULT_CLUSTER_CONFIG) - return conf - - -@pytest.fixture(scope='module') -def ydb_configurator(ydb_cluster_configuration): - return KikimrConfigGenerator(**ydb_cluster_configuration) - - -@pytest.fixture(scope='module') -def ydb_cluster(ydb_configurator, request): - module_name = request.module.__name__ - - logger.info("setup ydb_cluster for %s", module_name) - - logger.info("setup ydb_cluster as local") - cluster = KiKiMR( - configurator=ydb_configurator, - ) - cluster.is_local_test = True - - cluster.start() - - yield cluster - - logger.info("destroy ydb_cluster for %s", module_name) - cluster.stop() - - -@pytest.fixture(scope='module') -def ydb_root(ydb_cluster): - return os.path.join("/", ydb_cluster.domain_name) - - -@pytest.fixture(scope='module') -def ydb_private_client(ydb_cluster): - return ydb_cluster.client - - -@pytest.fixture(scope='function') -def ydb_safe_test_name(request): - return request.node.name.replace("[", "_").replace("]", "_") - - -@contextlib.contextmanager -def ydb_database_ctx(ydb_cluster, database_path, node_count=1, timeout_seconds=20, storage_pools={'hdd': 1}): - '''???''' - assert os.path.abspath(database_path), 'database_path should be an (absolute) path, not a database name' - - token = ydb_cluster.config.default_clusteradmin - - ydb_cluster.remove_database(database_path, timeout_seconds=timeout_seconds, token=token) - - logger.debug("create database %s: create path and declare internals", database_path) - - ydb_cluster.create_database(database_path, storage_pool_units_count=storage_pools, timeout_seconds=timeout_seconds, token=token) - - logger.debug("create database %s: start nodes and construct internals", database_path) - database_nodes = ydb_cluster.register_and_start_slots(database_path, node_count) - - logger.debug("create database %s: wait construction done", database_path) - ydb_cluster.wait_tenant_up(database_path, token=token) - - logger.debug("create database %s: database up", database_path) - yield database_path - - logger.debug("destroy database %s: remove path and dismantle internals", database_path) - ydb_cluster.remove_database(database_path, timeout_seconds=timeout_seconds, token=token) - - logger.debug("destroy database %s: stop nodes", database_path) - ydb_cluster.unregister_and_stop_slots(database_nodes) - - logger.debug("destroy database %s: database down", database_path) - - -def _ydb_database(cluster, database_path_base, unique_name): - database = os.path.join(database_path_base, unique_name) - - with ydb_database_ctx(cluster, database): - yield database - -@pytest.fixture(scope='function') -def ydb_database(ydb_cluster, ydb_root, ydb_safe_test_name): - yield from _ydb_database(ydb_cluster, ydb_root, ydb_safe_test_name) - - -@pytest.fixture(scope='module') -def ydb_database_module_scope(ydb_cluster, ydb_root, request): - # make unique database name from the test module name, ensuring that - # it does not contains the dots - unique_name = request.module.__name__.split('.')[-1] - yield from _ydb_database(ydb_cluster, ydb_root, unique_name) - - -@pytest.fixture(scope='module') -def ydb_endpoint(ydb_cluster): - return "%s:%s" % (ydb_cluster.nodes[1].host, ydb_cluster.nodes[1].port) - - -@pytest.fixture(scope='function') -def ydb_client(ydb_endpoint, request): - def _make_driver(database_path, **kwargs): - driver_config = DriverConfig(ydb_endpoint, database_path, **kwargs) - driver = Driver(driver_config) - - def stop_driver(): - driver.stop() - - request.addfinalizer(stop_driver) - return driver - - return _make_driver - - -@pytest.fixture(scope='function') -def ydb_client_session(ydb_client, request): - def _make_pool(database_path, **kwargs): - driver = ydb_client(database_path, **kwargs) - pool = SessionPool(driver) - - def stop_pool(): - pool.stop() - - request.addfinalizer(stop_pool) - return pool - - return _make_pool - - -# possible replacement for both ydb_client and ydb_client_session -# @pytest.fixture(scope='function') -# def ydb_database_and_client(ydb_database, ydb_endpoint): -# database_path = ydb_database -# with Driver(DriverConfig(ydb_endpoint, database_path)) as driver: -# with SessionPool(driver) as pool: -# yield database_path, pool |