From f28390cf884944fd78727a6813710e76cafcf8e3 Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Sat, 27 Jan 2024 23:12:26 +0800 Subject: [PATCH 1/3] feat: remove app timeout --- juju/model.py | 14 ++++++++++++-- tests/integration/test_application.py | 11 +++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/juju/model.py b/juju/model.py index 56af31e75..59637b74e 100644 --- a/juju/model.py +++ b/juju/model.py @@ -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 @@ -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\ @@ -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. diff --git a/tests/integration/test_application.py b/tests/integration/test_application.py index 05252d468..dfbcd2d4e 100644 --- a/tests/integration/test_application.py +++ b/tests/integration/test_application.py @@ -2,6 +2,7 @@ # Licensed under the Apache V2, see LICENCE file for details. from pathlib import Path +import asyncio import pytest import logging @@ -324,6 +325,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('ubuntu') + 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: From 0288f6c3c6ce0623e9afc662a97aae0d8281725d Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Sun, 28 Jan 2024 12:55:12 +0800 Subject: [PATCH 2/3] fix: lint --- juju/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/juju/model.py b/juju/model.py index 59637b74e..ccfd78588 100644 --- a/juju/model.py +++ b/juju/model.py @@ -1008,7 +1008,7 @@ async def remove_application( destroy_storage=False, no_wait=False, timeout=None - ): + ): """Removes the given application from the model. :param str app_name: Name of the application From 5b87acb76cece77c9ea9fdd123cd423f765e5601 Mon Sep 17 00:00:00 2001 From: Yanks Yoon <37652070+yanksyoon@users.noreply.github.com> Date: Wed, 31 Jan 2024 08:57:33 +0800 Subject: [PATCH 3/3] Deploy juju-qa-test Co-authored-by: Caner Derici --- tests/integration/test_application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_application.py b/tests/integration/test_application.py index dfbcd2d4e..abbb8be9d 100644 --- a/tests/integration/test_application.py +++ b/tests/integration/test_application.py @@ -328,7 +328,7 @@ async def test_app_remove_wait_flag(): @base.bootstrapped async def test_app_remove_timeout(): async with base.CleanModel() as model: - app = await model.deploy('ubuntu') + app = await model.deploy('juju-qa-test') await model.wait_for_idle(status="active") with pytest.raises(asyncio.TimeoutError):