userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
service.py
1
import
pathlib
2
import
typing
3
4
from
testsuite.environment
import
service, utils
5
6
from
.
import
connection
7
8
DEFAULT_CONFIG_SERVER_PORT = 27118
9
DEFAULT_MONGOS_PORT = 27217
10
DEFAULT_SHARD_PORT = 27119
11
DEFAULT_RS_INSTANCE_COUNT = 1
12
13
SERVICE_SCRIPT_PATH = pathlib.Path(__file__).parent.joinpath(
14
'scripts/service-mongo'
,
15
)
16
17
18
class
ServiceSettings
(typing.NamedTuple):
19
config_server_port: int
20
mongos_port: int
21
shard_port: int
22
rs_instance_count: int
23
24
def
get_connection_info(self) -> connection.ConnectionInfo:
25
return
connection.ConnectionInfo
(
26
host=
'localhost'
,
27
port=self.mongos_port,
28
)
29
30
31
def
create_mongo_service(
32
service_name,
33
working_dir,
34
settings: ServiceSettings |
None
=
None
,
35
env: dict[str, str] |
None
=
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(SERVICE_SCRIPT_PATH),
42
working_dir=working_dir,
43
environment={
44
'MONGO_TMPDIR'
: working_dir,
45
'MONGOS_PORT'
: str(settings.mongos_port),
46
'CONFIG_SERVER_PORT'
: str(settings.config_server_port),
47
'SHARD_PORT'
: str(settings.shard_port),
48
'MONGO_RS_INSTANCE_COUNT'
: str(settings.rs_instance_count),
49
**(env
or
{}),
50
},
51
check_ports=[
52
settings.config_server_port,
53
settings.mongos_port,
54
settings.shard_port,
55
],
56
)
57
58
59
def
get_service_settings():
60
return
ServiceSettings
(
61
utils.getenv_int(
62
key=
'TESTSUITE_MONGO_CONFIG_SERVER_PORT'
,
63
default=DEFAULT_CONFIG_SERVER_PORT,
64
),
65
utils.getenv_int(
66
key=
'TESTSUITE_MONGOS_PORT'
,
67
default=DEFAULT_MONGOS_PORT,
68
),
69
utils.getenv_int(
70
key=
'TESTSUITE_MONGO_SHARD_PORT'
,
71
default=DEFAULT_SHARD_PORT,
72
),
73
utils.getenv_int(
74
key=
'TESTSUITE_MONGO_RS_INSTANCE_COUNT'
,
75
default=DEFAULT_RS_INSTANCE_COUNT,
76
),
77
)
en
testsuite
databases
mongo
service.py
Generated on
for userver by
Doxygen
1.17.0