Skip to content

Commit 018a536

Browse files
authored
library/environment.py: increase etcd lease time (#105)
1 parent 694b8b0 commit 018a536

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

python/src/etos_api/library/environment.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ class Configuration(BaseModel):
3333
log_area_provider: str
3434

3535

36-
async def configure_testrun(configuration: Configuration) -> None:
36+
async def configure_testrun(configuration: Configuration, expire: int) -> None:
3737
"""Configure an ETOS testrun with the configuration passed by user.
3838
3939
:param configuration: The configuration to save.
40+
:param expire: etcd lease expiration time in seconds
4041
"""
4142
testrun = ETCDPath(f"/testrun/{configuration.suite_id}")
4243
providers = ETCDPath("/environment/provider")
@@ -45,30 +46,34 @@ async def configure_testrun(configuration: Configuration) -> None:
4546
providers.join(f"log-area/{configuration.log_area_provider}"),
4647
configuration.log_area_provider,
4748
testrun.join("provider/log-area"),
49+
expire,
4850
)
4951
await do_configure(
5052
providers.join(f"execution-space/{configuration.execution_space_provider}"),
5153
configuration.execution_space_provider,
5254
testrun.join("provider/execution-space"),
55+
expire,
5356
)
5457
await do_configure(
5558
providers.join(f"iut/{configuration.iut_provider}"),
5659
configuration.iut_provider,
5760
testrun.join("provider/iut"),
61+
expire,
5862
)
59-
await save_json(testrun.join("provider/dataset"), configuration.dataset)
63+
await save_json(testrun.join("provider/dataset"), configuration.dataset, expire)
6064

6165

62-
async def do_configure(path: ETCDPath, provider_id: str, testrun: ETCDPath) -> None:
66+
async def do_configure(path: ETCDPath, provider_id: str, testrun: ETCDPath, expire: int) -> None:
6367
"""Configure a provider based on provider ID and save it to a testrun.
6468
6569
:param path: Path to load provider from.
6670
:param provider_id: The ID of the provider to load.
6771
:param testrun: Where to store the loaded provider.
72+
:param expire: etcd lease expiration time in seconds
6873
"""
6974
if (provider := await load(path)) is None:
7075
raise AssertionError(f"{provider_id} does not exist")
71-
await save_json(testrun, provider)
76+
await save_json(testrun, provider, expire)
7277

7378

7479
async def load(path: ETCDPath) -> Optional[dict]:
@@ -82,7 +87,7 @@ async def load(path: ETCDPath) -> Optional[dict]:
8287
return None
8388

8489

85-
async def save_json(path: ETCDPath, data: dict, expire=3600) -> None:
90+
async def save_json(path: ETCDPath, data: dict, expire: int) -> None:
8691
"""Save data as json to an ETCD path.
8792
8893
:param path: The path to store data on.

python/src/etos_api/routers/v0/router.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ async def _start(etos: StartEtosRequest, span: Span) -> dict:
152152
log_area_provider=etos.log_area_provider,
153153
)
154154
try:
155-
await configure_testrun(config)
155+
# etcd lease expiration will have 10 minutes safety margin:
156+
etcd_lease_expiration_time = etos_library.debug.default_test_result_timeout + 10 * 60
157+
await configure_testrun(config, etcd_lease_expiration_time)
156158
except AssertionError as exception:
157159
LOGGER.critical(exception)
158160
raise HTTPException(

0 commit comments

Comments
 (0)