Skip to content

Commit

Permalink
Add quality of life feature ensure application removal at return
Browse files Browse the repository at this point in the history
fixes juju#656
  • Loading branch information
cderici committed Apr 6, 2022
1 parent b5c3185 commit 6ebc6a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions juju/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,21 @@ async def reset(self, force=False):
lambda: len(self.machines) == 0
)

async def remove_application(self, app_name, block_until_done=False):
"""Removes the given application from the model.
:param str app_name: Name of the application
:param bool block_until_done: Ensure the app is removed from the
model when returned
"""
if app_name not in self.applications:
raise JujuError("Given application doesn't seem to appear in the\
model: %s\nCurrent applications are: %s" %
(app_name, self.applications))
await self.applications[app_name].remove()
if block_until_done:
await self.block_until(lambda: app_name not in self.applications)

async def block_until(self, *conditions, timeout=None, wait_period=0.5):
"""Return only after all conditions are true.
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,15 @@ async def test_trusted(event_loop):
await ubuntu_app.set_trusted(False)
trusted = await ubuntu_app.get_trusted()
assert trusted is False


@base.bootstrapped
@pytest.mark.asyncio
async def test_app_remove_wait_flag(event_loop):
async with base.CleanModel() as model:
app = await model.deploy('cs:ubuntu')
a_name = app.name
await model.wait_for_idle(status="active")

await model.remove_application(app.name, block_until_done=True)
assert a_name not in model.applications

0 comments on commit 6ebc6a6

Please sign in to comment.