Skip to content

Commit 02ee311

Browse files
authored
Dynamic nodes count for not kube clusters (#14558)
1 parent e6c9446 commit 02ee311

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

ydb/tests/functional/tpc/lib/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def setup_cluster(cls) -> None:
2020
YdbCluster.reset(
2121
ydb_endpoint=f'grpc://{node.host}:{node.grpc_port}',
2222
ydb_database=f'{cls.cluster.domain_name}/test_db',
23-
ydb_mon_port=node.mon_port
23+
ydb_mon_port=node.mon_port,
24+
dyn_nodes_count=1
2425
)
2526
db = f'/{YdbCluster.ydb_database}'
2627
cls.cluster.create_database(
@@ -29,7 +30,7 @@ def setup_cluster(cls) -> None:
2930
'hdd': 1
3031
}
3132
)
32-
cls.cluster.register_and_start_slots(db, count=1)
33+
cls.cluster.register_and_start_slots(db, count=YdbCluster.get_dyn_nodes_count())
3334
cls.cluster.wait_tenant_up(db)
3435

3536
@classmethod

ydb/tests/olap/lib/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ PY3_LIBRARY()
1111
PEERDIR(
1212
contrib/python/allure-pytest
1313
contrib/python/allure-python-commons
14+
contrib/python/PyYAML
1415
contrib/python/pytz
1516
contrib/python/requests
1617
library/python/testing/yatest_common

ydb/tests/olap/lib/ydb_cluster.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import logging
44
import os
55
import requests
6-
from ydb.tests.olap.lib.utils import get_external_param
6+
import yaml
77
import ydb
8+
from ydb.tests.olap.lib.utils import get_external_param
89
from copy import deepcopy
910
from time import sleep, time
1011
from typing import List, Optional
@@ -56,6 +57,7 @@ def __init__(self, desc: dict):
5657
ydb_mon_port = 8765
5758
tables_path = get_external_param('tables-path', 'olap_yatests')
5859
_monitoring_urls: list[YdbCluster.MonitoringUrl] = None
60+
_dyn_nodes_count: Optional[int] = None
5961

6062
@classmethod
6163
def get_monitoring_urls(cls) -> list[YdbCluster.MonitoringUrl]:
@@ -154,10 +156,11 @@ def _create_ydb_driver(endpoint, database, oauth=None, iam_file=None):
154156
raise
155157

156158
@classmethod
157-
def reset(cls, ydb_endpoint, ydb_database, ydb_mon_port):
159+
def reset(cls, ydb_endpoint, ydb_database, ydb_mon_port, dyn_nodes_count):
158160
cls.ydb_endpoint = ydb_endpoint
159161
cls.ydb_database = ydb_database
160162
cls.ydb_mon_port = ydb_mon_port
163+
cls._dyn_nodes_count = dyn_nodes_count
161164
cls._ydb_driver = None
162165

163166
@classmethod
@@ -225,6 +228,25 @@ def execute_single_result_query(cls, query, timeout=10):
225228
LOGGER.error("Cannot connect to YDB")
226229
raise
227230

231+
@classmethod
232+
def get_dyn_nodes_count(cls) -> int:
233+
if cls._dyn_nodes_count is None:
234+
cls._dyn_nodes_count = 0
235+
if os.getenv('EXPECTED_DYN_NODES_COUNT'):
236+
cls._dyn_nodes_count = int(os.getenv('EXPECTED_DYN_NODES_COUNT'))
237+
elif os.getenv('CLUSTER_CONFIG'):
238+
with open(os.getenv('CLUSTER_CONFIG'), 'r') as r:
239+
yaml_config = yaml.safe_load(r.read())
240+
for domain in yaml_config['domains']:
241+
if domain["domain_name"] == cls.ydb_database:
242+
cls._dyn_nodes_count = domain["domain_name"]["dynamic_slots"]
243+
for db in domain['databases']:
244+
if f'{domain["domain_name"]}/{db["name"]}' == cls.ydb_database:
245+
for cu in db['compute_units']:
246+
cls._dyn_nodes_count += cu['count']
247+
248+
return cls._dyn_nodes_count
249+
228250
@classmethod
229251
@allure.step('Check if YDB alive')
230252
def check_if_ydb_alive(cls, timeout=10, balanced_paths=None) -> tuple[str, str]:
@@ -241,11 +263,10 @@ def _check_node(n: YdbCluster.Node):
241263
warnings = []
242264
try:
243265
nodes = cls.get_cluster_nodes(db_only=True)
244-
expected_nodes_count = os.getenv('EXPECTED_DYN_NODES_COUNT')
266+
expected_nodes_count = cls.get_dyn_nodes_count()
245267
nodes_count = len(nodes)
246268
if expected_nodes_count:
247269
LOGGER.debug(f'Expected nodes count: {expected_nodes_count}')
248-
expected_nodes_count = int(expected_nodes_count)
249270
if nodes_count < expected_nodes_count:
250271
errors.append(f"{expected_nodes_count - nodes_count} nodes from {expected_nodes_count} don't alive")
251272
ok_node_count = 0

ydb/tests/olap/scenario/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class YdbClusterInstance():
2424
_temp_ydb_cluster = None
2525
_endpoint = None
2626
_database = None
27+
_dyn_nodes_count = None
2728

2829
def __init__(self, endpoint, database, config):
2930
if endpoint is not None:
@@ -38,6 +39,7 @@ def __init__(self, endpoint, database, config):
3839
self._database = config.domain_name
3940
self._mon_port = node.mon_port
4041
self._temp_ydb_cluster = cluster
42+
self._dyn_nodes_count = len(cluster.nodes)
4143
LOGGER.info(f'Using YDB, endpoint:{self._endpoint}, database:{self._database}')
4244

4345
def endpoint(self):
@@ -46,6 +48,9 @@ def endpoint(self):
4648
def database(self):
4749
return self._database
4850

51+
def dyn_nodes_count(self):
52+
return self._dyn_nodes_count
53+
4954
def mon_port(self):
5055
return self._mon_port
5156

@@ -65,7 +70,7 @@ def setup_class(cls):
6570
ydb_endpoint = get_external_param('ydb-endpoint', None)
6671
ydb_database = get_external_param('ydb-db', "").lstrip('/')
6772
cls._ydb_instance = YdbClusterInstance(ydb_endpoint, ydb_database, cls._get_cluster_config())
68-
YdbCluster.reset(cls._ydb_instance.endpoint(), cls._ydb_instance.database(), cls._ydb_instance.mon_port())
73+
YdbCluster.reset(cls._ydb_instance.endpoint(), cls._ydb_instance.database(), cls._ydb_instance.mon_port(), cls._ydb_instance.dyn_nodes_count())
6974
if not external_param_is_true('reuse-tables'):
7075
ScenarioTestHelper(None).remove_path(cls.get_suite_name())
7176

0 commit comments

Comments
 (0)