userver: /data/code/userver/testsuite/pytest_plugins/pytest_userver/plugins/ydb/service.py Source File
Loading...
Searching...
No Matches
service.py
1import dataclasses
2import os
3import pathlib
4import typing
5
6from testsuite.environment import service
7from testsuite.environment import utils
8
9
10DEFAULT_HOST = 'localhost'
11DEFAULT_GRPC_TLS_PORT = 2135
12DEFAULT_GRPC_PORT = 2136
13DEFAULT_MON_PORT = 8765
14DEFAULT_DATABASE = 'local'
15DEFAULT_CONTAINER_NAME = 'ydb-local-testsuite'
16DEFAULT_DOCKER_IMAGE = 'cr.yandex/yc/yandex-docker-local-ydb:latest'
17
18PLUGIN_DIR = pathlib.Path(__file__).parent
19SCRIPTS_DIR = PLUGIN_DIR.joinpath('scripts')
20
21
22@dataclasses.dataclass(frozen=True)
24 host: str
25 grpc_port: int
26 mon_port: int
27 ic_port: int
28 database: str
29
30
31def create_ydb_service(
32 service_name: str,
33 working_dir: str,
34 settings: typing.Optional[ServiceSettings] = None,
35 env: typing.Optional[typing.Dict[str, str]] = None,
36):
37 if settings is None:
38 settings = get_service_settings()
39 return service.ScriptService(
40 service_name=service_name,
41 script_path=str(SCRIPTS_DIR.joinpath('service-ydb')),
42 working_dir=working_dir,
43 environment={
44 'YDB_TMPDIR': working_dir,
45 'YDB_SCRIPTS_DIR': str(SCRIPTS_DIR),
46 'YDB_HOSTNAME': settings.host,
47 'YDB_GRPC_PORT': str(settings.grpc_port),
48 'YDB_GRPC_TLS_PORT': str(DEFAULT_GRPC_TLS_PORT),
49 'YDB_MON_PORT': str(settings.mon_port),
50 'YDB_CONTAINER_NAME': DEFAULT_CONTAINER_NAME,
51 'YDB_DOCKER_IMAGE': DEFAULT_DOCKER_IMAGE,
52 **(env or {}),
53 },
54 check_ports=[settings.grpc_port, settings.mon_port],
55 )
56
57
58def get_service_settings():
59 return ServiceSettings(
60 host=os.getenv('TESTSUITE_YDB_HOST', DEFAULT_HOST),
61 grpc_port=utils.getenv_int(
62 'TESTSUITE_YDB_GRPC_PORT', DEFAULT_GRPC_PORT,
63 ),
64 mon_port=utils.getenv_int('TESTSUITE_YDB_MON_PORT', DEFAULT_MON_PORT),
65 ic_port=utils.getenv_int('TESTSUITE_YDB_IC_PORT', 0),
66 database=os.getenv('TESTSUITE_YDB_DATABASE', DEFAULT_DATABASE),
67 )