Skip to content

Commit 6ebc6a6

Browse files
committed
Add quality of life feature ensure application removal at return
fixes #656
1 parent b5c3185 commit 6ebc6a6

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

juju/model.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,21 @@ async def reset(self, force=False):
875875
lambda: len(self.machines) == 0
876876
)
877877

878+
async def remove_application(self, app_name, block_until_done=False):
879+
"""Removes the given application from the model.
880+
881+
:param str app_name: Name of the application
882+
:param bool block_until_done: Ensure the app is removed from the
883+
model when returned
884+
"""
885+
if app_name not in self.applications:
886+
raise JujuError("Given application doesn't seem to appear in the\
887+
model: %s\nCurrent applications are: %s" %
888+
(app_name, self.applications))
889+
await self.applications[app_name].remove()
890+
if block_until_done:
891+
await self.block_until(lambda: app_name not in self.applications)
892+
878893
async def block_until(self, *conditions, timeout=None, wait_period=0.5):
879894
"""Return only after all conditions are true.
880895

tests/integration/test_application.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,15 @@ async def test_trusted(event_loop):
235235
await ubuntu_app.set_trusted(False)
236236
trusted = await ubuntu_app.get_trusted()
237237
assert trusted is False
238+
239+
240+
@base.bootstrapped
241+
@pytest.mark.asyncio
242+
async def test_app_remove_wait_flag(event_loop):
243+
async with base.CleanModel() as model:
244+
app = await model.deploy('cs:ubuntu')
245+
a_name = app.name
246+
await model.wait_for_idle(status="active")
247+
248+
await model.remove_application(app.name, block_until_done=True)
249+
assert a_name not in model.applications

0 commit comments

Comments
 (0)