Skip to content

Commit f28390c

Browse files
committed
feat: remove app timeout
1 parent 32ce250 commit f28390c

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
@@ -2,6 +2,7 @@
22
# Licensed under the Apache V2, see LICENCE file for details.
33

44
from pathlib import Path
5+
import asyncio
56

67
import pytest
78
import logging
@@ -324,6 +325,16 @@ async def test_app_remove_wait_flag():
324325
assert a_name not in model.applications
325326

326327

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

0 commit comments

Comments
 (0)