Skip to content

Commit 4c4a673

Browse files
authored
Refactor harness (#9211)
1 parent 2313a5e commit 4c4a673

File tree

5 files changed

+22
-37
lines changed

5 files changed

+22
-37
lines changed

ydb/tests/functional/encryption/test_encryption.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def setup_class(cls):
7474
)
7575
)
7676
cls.cluster.start()
77-
cls.discovery_endpoint = "%s:%s" % (cls.cluster.nodes[1].hostname, cls.cluster.nodes[1].grpc_port)
77+
cls.discovery_endpoint = "%s:%s" % (cls.cluster.nodes[1].host, cls.cluster.nodes[1].grpc_port)
7878

7979
def test_simple_encryption(self):
8080
databases = []

ydb/tests/functional/query_cache/test_query_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def setup_class(cls):
2828
cls.config.yaml_config["table_service_config"] = {"compile_query_cache_size": QUERY_CACHE_SIZE}
2929
cls.cluster = kikimr_cluster_factory(configurator=cls.config)
3030
cls.cluster.start()
31-
cls.discovery_endpoint = "%s:%s" % (cls.cluster.nodes[1].hostname, cls.cluster.nodes[1].grpc_port)
31+
cls.discovery_endpoint = "%s:%s" % (cls.cluster.nodes[1].host, cls.cluster.nodes[1].grpc_port)
3232
cls.driver = ydb.Driver(endpoint=cls.discovery_endpoint, database="/Root", credentials=ydb.AnonymousCredentials())
3333
cls.driver.wait(timeout=5)
3434
cls.pool = ydb.SessionPool(cls.driver)

ydb/tests/library/harness/daemon.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
logger = logging.getLogger(__name__)
1818

1919

20-
def extract_stderr_details(stderr_file, max_lines=0):
20+
def _extract_stderr_details(stderr_file, max_lines=0):
2121
if max_lines == 0:
2222
return []
2323

@@ -43,7 +43,7 @@ def __init__(self, message, stdout, stderr, exit_code, max_stderr_lines=0):
4343
"Stdout file name: \n{}".format(stdout if stdout is not None else "is not present."),
4444
"Stderr file name: \n{}".format(stderr if stderr is not None else "is not present."),
4545
]
46-
+ extract_stderr_details(stderr, max_stderr_lines)
46+
+ _extract_stderr_details(stderr, max_stderr_lines)
4747
)
4848
)
4949

@@ -54,6 +54,7 @@ def __init__(self, exceptions):
5454

5555

5656
class Daemon(object):
57+
"""Local process executed as process in current host"""
5758
def __init__(
5859
self,
5960
command,
@@ -208,6 +209,7 @@ def kill(self):
208209

209210
@six.add_metaclass(abc.ABCMeta)
210211
class ExternalNodeDaemon(object):
212+
"""External daemon, executed as process in separate host, managed via ssh"""
211213
def __init__(self, host):
212214
self._host = host
213215
self._ssh_username = param_constants.ssh_username
@@ -263,12 +265,6 @@ def cleanup_logs(self):
263265
'sudo rm -rf {}/* && sudo service rsyslog restart'.format(self.logs_directory), raise_on_error=True
264266
)
265267

266-
def sky_get_and_move(self, rb_torrent, item_to_move, target_path):
267-
self.ssh_command(['sky get -d %s %s' % (self._artifacts_path, rb_torrent)], raise_on_error=True)
268-
self.ssh_command(
269-
['sudo mv %s %s' % (os.path.join(self._artifacts_path, item_to_move), target_path)], raise_on_error=True
270-
)
271-
272268
def send_signal(self, signal):
273269
self.ssh_command(
274270
"ps aux | grep %d | grep -v daemon | grep -v grep | awk '{ print $2 }' | xargs sudo kill -%d"

ydb/tests/library/harness/kikimr_config.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
])
3434

3535

36-
def get_fqdn():
36+
def _get_fqdn():
3737
hostname = socket.gethostname()
3838
addrinfo = socket.getaddrinfo(hostname, None, socket.AF_UNSPEC, 0, 0, socket.AI_CANONNAME)
3939
for ai in addrinfo:
@@ -44,7 +44,7 @@ def get_fqdn():
4444

4545

4646
# GRPC_SERVER:DEBUG,TICKET_PARSER:WARN,KQP_COMPILE_ACTOR:DEBUG
47-
def get_additional_log_configs():
47+
def _get_additional_log_configs():
4848
log_configs = os.getenv('YDB_ADDITIONAL_LOG_CONFIGS', '')
4949
rt = {}
5050

@@ -55,13 +55,13 @@ def get_additional_log_configs():
5555
return rt
5656

5757

58-
def get_grpc_host():
58+
def _get_grpc_host():
5959
if sys.platform == "darwin":
6060
return "localhost"
6161
return "[::]"
6262

6363

64-
def load_default_yaml(default_tablet_node_ids, ydb_domain_name, static_erasure, log_configs):
64+
def _load_default_yaml(default_tablet_node_ids, ydb_domain_name, static_erasure, log_configs):
6565
data = read_binary(__name__, "resources/default_yaml.yml")
6666
if isinstance(data, bytes):
6767
data = data.decode('utf-8')
@@ -73,7 +73,7 @@ def load_default_yaml(default_tablet_node_ids, ydb_domain_name, static_erasure,
7373
ydb_default_log_level=int(LogLevels.from_string(os.getenv("YDB_DEFAULT_LOG_LEVEL", "NOTICE"))),
7474
ydb_domain_name=ydb_domain_name,
7575
ydb_static_erasure=static_erasure,
76-
ydb_grpc_host=get_grpc_host(),
76+
ydb_grpc_host=_get_grpc_host(),
7777
ydb_pq_topics_are_first_class_citizen=bool(os.getenv("YDB_PQ_TOPICS_ARE_FIRST_CLASS_CITIZEN", "true")),
7878
ydb_pq_cluster_table_path=str(os.getenv("YDB_PQ_CLUSTER_TABLE_PATH", "")),
7979
ydb_pq_version_table_path=str(os.getenv("YDB_PQ_VERSION_TABLE_PATH", "")),
@@ -97,7 +97,7 @@ def _load_yaml_config(filename):
9797
return yaml.safe_load(_read_file(filename))
9898

9999

100-
def use_in_memory_pdisks_var(pdisk_store_path, use_in_memory_pdisks):
100+
def _use_in_memory_pdisks_var(pdisk_store_path, use_in_memory_pdisks):
101101
if os.getenv('YDB_USE_IN_MEMORY_PDISKS') is not None:
102102
return os.getenv('YDB_USE_IN_MEMORY_PDISKS') == "true"
103103

@@ -120,9 +120,7 @@ def __init__(
120120
output_path=None,
121121
enable_pq=True,
122122
pq_client_service_types=None,
123-
slot_count=0,
124123
pdisk_store_path=None,
125-
version=None,
126124
enable_sqs=False,
127125
domain_name='Root',
128126
suppress_version_check=True,
@@ -168,7 +166,6 @@ def __init__(
168166
if extra_grpc_services is None:
169167
extra_grpc_services = []
170168

171-
self._version = version
172169
self.use_log_files = use_log_files
173170
self.suppress_version_check = suppress_version_check
174171
self._pdisk_store_path = pdisk_store_path
@@ -184,7 +181,7 @@ def __init__(
184181
self._pdisks_info = []
185182
if self.__grpc_ssl_enable:
186183
self.__grpc_tls_data_path = grpc_tls_data_path or yatest_common.output_path()
187-
cert_pem, key_pem = tls_tools.generate_selfsigned_cert(get_fqdn())
184+
cert_pem, key_pem = tls_tools.generate_selfsigned_cert(_get_fqdn())
188185
self.__grpc_tls_ca = cert_pem
189186
self.__grpc_tls_key = key_pem
190187
self.__grpc_tls_cert = cert_pem
@@ -204,20 +201,19 @@ def __init__(
204201
self.state_storage_rings = state_storage_rings
205202
if self.state_storage_rings is None:
206203
self.state_storage_rings = copy.deepcopy(self.__node_ids[: 9 if erasure == Erasure.MIRROR_3_DC else 8])
207-
self.__use_in_memory_pdisks = use_in_memory_pdisks_var(pdisk_store_path, use_in_memory_pdisks)
204+
self.__use_in_memory_pdisks = _use_in_memory_pdisks_var(pdisk_store_path, use_in_memory_pdisks)
208205
self.__pdisks_directory = os.getenv('YDB_PDISKS_DIRECTORY')
209206
self.static_erasure = erasure
210207
self.domain_name = domain_name
211208
self.__number_of_pdisks_per_node = 1 + len(dynamic_pdisks)
212209
self.__load_udfs = load_udfs
213210
self.__udfs_path = udfs_path
214-
self.__slot_count = slot_count
215211
self._dcs = [1]
216212
if erasure == Erasure.MIRROR_3_DC:
217213
self._dcs = [1, 2, 3]
218214

219215
self.__additional_log_configs = {} if additional_log_configs is None else additional_log_configs
220-
self.__additional_log_configs.update(get_additional_log_configs())
216+
self.__additional_log_configs.update(_get_additional_log_configs())
221217
if pg_compatible_expirement:
222218
self.__additional_log_configs.update({
223219
'PGWIRE': LogLevels.from_string('DEBUG'),
@@ -236,7 +232,7 @@ def __init__(
236232

237233
self.__bs_cache_file_path = bs_cache_file_path
238234

239-
self.yaml_config = load_default_yaml(self.__node_ids, self.domain_name, self.static_erasure, self.__additional_log_configs)
235+
self.yaml_config = _load_default_yaml(self.__node_ids, self.domain_name, self.static_erasure, self.__additional_log_configs)
240236

241237
if overrided_actor_system_config:
242238
self.yaml_config["actor_system_config"] = overrided_actor_system_config

ydb/tests/library/harness/kikimr_runner.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,6 @@ def send_signal(self, signal):
215215
def host(self):
216216
return 'localhost'
217217

218-
@property
219-
def hostname(self):
220-
return kikimr_config.get_fqdn()
221-
222218
@property
223219
def port(self):
224220
return self.grpc_port
@@ -380,19 +376,16 @@ def __register_node(self):
380376
)
381377
return self._nodes[node_index]
382378

383-
def register_slots(self, database, count=1, encryption_key=None):
384-
return [self.register_slot(database, encryption_key) for _ in range(count)]
379+
def __register_slots(self, database, count=1, encryption_key=None):
380+
return [self.__register_slot(database, encryption_key) for _ in range(count)]
385381

386382
def register_and_start_slots(self, database, count=1, encryption_key=None):
387-
slots = self.register_slots(database, count, encryption_key)
383+
slots = self.__register_slots(database, count, encryption_key)
388384
for slot in slots:
389385
slot.start()
390386
return slots
391387

392-
def register_slot(self, tenant_affiliation=None, encryption_key=None):
393-
return self._register_slot(tenant_affiliation, encryption_key)
394-
395-
def _register_slot(self, tenant_affiliation=None, encryption_key=None):
388+
def __register_slot(self, tenant_affiliation=None, encryption_key=None):
396389
slot_index = next(self._slot_index_allocator)
397390
node_broker_port = (
398391
self.nodes[1].grpc_ssl_port if self.__configurator.grpc_ssl_enable
@@ -412,12 +405,12 @@ def _register_slot(self, tenant_affiliation=None, encryption_key=None):
412405
)
413406
return self._slots[slot_index]
414407

415-
def unregister_slots(self, slots):
408+
def __unregister_slots(self, slots):
416409
for i in slots:
417410
del self._slots[i.node_id]
418411

419412
def unregister_and_stop_slots(self, slots):
420-
self.unregister_slots(slots)
413+
self.__unregister_slots(slots)
421414
for i in slots:
422415
i.stop()
423416

0 commit comments

Comments
 (0)