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