3
3
import logging
4
4
import os
5
5
import requests
6
- from ydb . tests . olap . lib . utils import get_external_param
6
+ import yaml
7
7
import ydb
8
+ from ydb .tests .olap .lib .utils import get_external_param
8
9
from copy import deepcopy
9
10
from time import sleep , time
10
11
from typing import List , Optional
@@ -56,6 +57,7 @@ def __init__(self, desc: dict):
56
57
ydb_mon_port = 8765
57
58
tables_path = get_external_param ('tables-path' , 'olap_yatests' )
58
59
_monitoring_urls : list [YdbCluster .MonitoringUrl ] = None
60
+ _dyn_nodes_count : Optional [int ] = None
59
61
60
62
@classmethod
61
63
def get_monitoring_urls (cls ) -> list [YdbCluster .MonitoringUrl ]:
@@ -154,10 +156,11 @@ def _create_ydb_driver(endpoint, database, oauth=None, iam_file=None):
154
156
raise
155
157
156
158
@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 ):
158
160
cls .ydb_endpoint = ydb_endpoint
159
161
cls .ydb_database = ydb_database
160
162
cls .ydb_mon_port = ydb_mon_port
163
+ cls ._dyn_nodes_count = dyn_nodes_count
161
164
cls ._ydb_driver = None
162
165
163
166
@classmethod
@@ -225,6 +228,25 @@ def execute_single_result_query(cls, query, timeout=10):
225
228
LOGGER .error ("Cannot connect to YDB" )
226
229
raise
227
230
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
+
228
250
@classmethod
229
251
@allure .step ('Check if YDB alive' )
230
252
def check_if_ydb_alive (cls , timeout = 10 , balanced_paths = None ) -> tuple [str , str ]:
@@ -241,11 +263,10 @@ def _check_node(n: YdbCluster.Node):
241
263
warnings = []
242
264
try :
243
265
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 ( )
245
267
nodes_count = len (nodes )
246
268
if expected_nodes_count :
247
269
LOGGER .debug (f'Expected nodes count: { expected_nodes_count } ' )
248
- expected_nodes_count = int (expected_nodes_count )
249
270
if nodes_count < expected_nodes_count :
250
271
errors .append (f"{ expected_nodes_count - nodes_count } nodes from { expected_nodes_count } don't alive" )
251
272
ok_node_count = 0
0 commit comments