Skip to content

Commit

Permalink
Merge pull request #1018 from yanksyoon/feat/remove_application_timeout
Browse files Browse the repository at this point in the history
#1018

#### Description

*<Please add why this change is needed and what it does.>*
Adds timeout parameter to `model.remove_application()`
Addresses #855 

*<Fixes: >*


#### QA Steps

*<Commands / tests / steps to run to verify that the change works:>*
```
tox -e integration -- -k test_app_remove_timeout
```

All CI tests need to pass.

*<Please note that most likely an additional test will be required by the reviewers for any change that's not a one liner to land.>*

#### Notes & Discussion

*<Additional notes for the reviewers if needed. Please delete section if not applicable.>*
  • Loading branch information
jujubot authored Feb 1, 2024
2 parents 66e92a3 + 76b9361 commit 16149db
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 12 additions & 2 deletions juju/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,15 @@ async def remove_storage(self, *storage_ids, force=False, destroy_storage=False)
if ret.results[0].error:
raise JujuError(ret.results[0].error.message)

async def remove_application(self, app_name, block_until_done=False, force=False, destroy_storage=False, no_wait=False):
async def remove_application(
self,
app_name,
block_until_done=False,
force=False,
destroy_storage=False,
no_wait=False,
timeout=None
):
"""Removes the given application from the model.
:param str app_name: Name of the application
Expand All @@ -1009,6 +1017,8 @@ async def remove_application(self, app_name, block_until_done=False, force=False
:param bool no_wait: Rush through application removal without waiting for each individual step to complete (=false)
:param bool block_until_done: Ensure the app is removed from the
model when returned
:param int timeout: Raise asyncio.exceptions.TimeoutError if the application is not removed
within the timeout period.
"""
if app_name not in self.applications:
raise JujuError("Given application doesn't seem to appear in the\
Expand All @@ -1019,7 +1029,7 @@ async def remove_application(self, app_name, block_until_done=False, force=False
no_wait=no_wait,
)
if block_until_done:
await self.block_until(lambda: app_name not in self.applications)
await self.block_until(lambda: app_name not in self.applications, timeout=timeout)

async def block_until(self, *conditions, timeout=None, wait_period=0.5):
"""Return only after all conditions are true.
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import logging
from pathlib import Path
import asyncio

import pytest

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


@base.bootstrapped
async def test_app_remove_timeout():
async with base.CleanModel() as model:
app = await model.deploy('juju-qa-test')
await model.wait_for_idle(status="active")

with pytest.raises(asyncio.TimeoutError):
await model.remove_application(app.name, block_until_done=True, timeout=1)


@base.bootstrapped
async def test_app_charm_name():
async with base.CleanModel() as model:
Expand Down

0 comments on commit 16149db

Please sign in to comment.