Skip to content

Commit 6a2a7ab

Browse files
committed
feat: remove app timeout
1 parent 06c0e7a commit 6a2a7ab

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

juju/model.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,15 @@ async def remove_storage(self, *storage_ids, force=False, destroy_storage=False)
10001000
if ret.results[0].error:
10011001
raise JujuError(ret.results[0].error.message)
10021002

1003-
async def remove_application(self, app_name, block_until_done=False, force=False, destroy_storage=False, no_wait=False):
1003+
async def remove_application(
1004+
self,
1005+
app_name,
1006+
block_until_done=False,
1007+
force=False,
1008+
destroy_storage=False,
1009+
no_wait=False,
1010+
timeout=None
1011+
):
10041012
"""Removes the given application from the model.
10051013
10061014
:param str app_name: Name of the application
@@ -1009,6 +1017,8 @@ async def remove_application(self, app_name, block_until_done=False, force=False
10091017
:param bool no_wait: Rush through application removal without waiting for each individual step to complete (=false)
10101018
:param bool block_until_done: Ensure the app is removed from the
10111019
model when returned
1020+
:param int timeout: Raise asyncio.exceptions.TimeoutError if the application is not removed
1021+
within the timeout period.
10121022
"""
10131023
if app_name not in self.applications:
10141024
raise JujuError("Given application doesn't seem to appear in the\
@@ -1019,7 +1029,7 @@ async def remove_application(self, app_name, block_until_done=False, force=False
10191029
no_wait=no_wait,
10201030
)
10211031
if block_until_done:
1022-
await self.block_until(lambda: app_name not in self.applications)
1032+
await self.block_until(lambda: app_name not in self.applications, timeout=timeout)
10231033

10241034
async def block_until(self, *conditions, timeout=None, wait_period=0.5):
10251035
"""Return only after all conditions are true.

tests/integration/test_application.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import logging
55
from pathlib import Path
6+
import asyncio
67

78
import pytest
89

@@ -326,6 +327,16 @@ async def test_app_remove_wait_flag():
326327
assert a_name not in model.applications
327328

328329

330+
@base.bootstrapped
331+
async def test_app_remove_timeout():
332+
async with base.CleanModel() as model:
333+
app = await model.deploy('ubuntu')
334+
await model.wait_for_idle(status="active")
335+
336+
with pytest.raises(asyncio.TimeoutError):
337+
await model.remove_application(app.name, block_until_done=True, timeout=1)
338+
339+
329340
@base.bootstrapped
330341
async def test_app_charm_name():
331342
async with base.CleanModel() as model:

0 commit comments

Comments
 (0)