From: Dario Faccin Date: Sat, 8 Jul 2023 11:36:55 +0000 (+0200) Subject: Update Remove charm activity checking the model X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F53%2F13653%2F7;p=osm%2FLCM.git Update Remove charm activity checking the model If the model does not exist, do not raise an exception Change-Id: I5f4519391460db2784325bb4896f2c153d481cb3 Signed-off-by: Dario Faccin --- diff --git a/osm_lcm/temporal/juju_paas_activities.py b/osm_lcm/temporal/juju_paas_activities.py index cb96fd9..a5c4dfb 100644 --- a/osm_lcm/temporal/juju_paas_activities.py +++ b/osm_lcm/temporal/juju_paas_activities.py @@ -279,6 +279,8 @@ class RemoveCharmImpl(RemoveCharm): controller: Controller = await self.juju_controller._get_controller( activity_input.vim_uuid ) + if model_name not in (await controller.list_models()): + return model = await controller.get_model(model_name) if app_name not in model.applications: return @@ -287,6 +289,7 @@ class RemoveCharmImpl(RemoveCharm): block_until_done=False, force=force_remove, no_wait=force_remove, + destroy_storage=True, ) @@ -294,12 +297,10 @@ class CheckCharmIsRemovedImpl(CheckCharmIsRemoved): @activity.defn(name=CheckCharmIsRemoved.__name__) async def __call__(self, activity_input: CheckCharmIsRemoved.Input) -> None: controller = await self.juju_controller._get_controller(activity_input.vim_uuid) + if activity_input.model_name not in (await controller.list_models()): + return model = await controller.get_model(activity_input.model_name) app_name = activity_input.application_name - - removed = False - while not removed: + while app_name in model.applications: activity.heartbeat() await asyncio.sleep(activity_input.poll_interval) - if app_name not in model.applications: - removed = True diff --git a/osm_lcm/tests/test_juju_paas_activities.py b/osm_lcm/tests/test_juju_paas_activities.py index 0f24e82..b3913c0 100644 --- a/osm_lcm/tests/test_juju_paas_activities.py +++ b/osm_lcm/tests/test_juju_paas_activities.py @@ -467,6 +467,7 @@ class TestRemoveCharm(TestJujuPaasActivitiesBase): force_remove=is_forced, ) self.add_application(self.app_name) + self.controller.list_models.return_value = [namespace] await self.env.run( self.remove_charm, remove_charm_input, @@ -476,6 +477,7 @@ class TestRemoveCharm(TestJujuPaasActivitiesBase): block_until_done=False, force=is_forced, no_wait=is_forced, + destroy_storage=True, ) async def test_remove_charm__app_does_not_exist(self): @@ -485,12 +487,27 @@ class TestRemoveCharm(TestJujuPaasActivitiesBase): model_name=namespace, force_remove=False, ) + self.controller.list_models.return_value = [namespace] await self.env.run( self.remove_charm, remove_charm_input, ) self.model.remove_application.assert_not_called() + async def test_remove_charm__model_does_not_exist(self): + remove_charm_input = RemoveCharmImpl.Input( + vim_uuid=vim_content["_id"], + application_name=self.app_name, + model_name="not-existing-model", + force_remove=False, + ) + self.controller.list_models.return_value = [namespace] + await self.env.run( + self.remove_charm, + remove_charm_input, + ) + self.controller.get_model.assert_not_called() + async def test_remove_charm__juju_error_occurred__app_is_not_removed(self): remove_charm_input = RemoveCharmImpl.Input( vim_uuid=vim_content["_id"], @@ -499,6 +516,7 @@ class TestRemoveCharm(TestJujuPaasActivitiesBase): force_remove=False, ) self.add_application(self.app_name) + self.controller.list_models.return_value = [namespace] self.controller.get_model.side_effect = JujuError() with self.assertRaises(JujuError): await self.env.run( @@ -525,11 +543,11 @@ class TestCheckCharmIsRemoved(TestJujuPaasActivitiesBase): async def test_check_is_charm_removed__nominal_case(self): arg = CheckCharmIsRemovedImpl.Input( application_name=self.application_name, - model_name="model", + model_name=namespace, vim_uuid="vim-uuid", poll_interval=0, ) - + self.controller.list_models.return_value = [namespace] type(self.model).applications = mock.PropertyMock( side_effect=[self.model.applications, {}] ) @@ -539,10 +557,23 @@ class TestCheckCharmIsRemoved(TestJujuPaasActivitiesBase): async def test_check_is_charm_removed__cancel(self): arg = CheckCharmIsRemovedImpl.Input( application_name=self.application_name, - model_name="model", + model_name=namespace, vim_uuid="vim-uuid", poll_interval=0, ) + self.controller.list_models.return_value = [namespace] with self.assertRaises(asyncio.exceptions.CancelledError): await self.env.run(self.check_charm_is_removed.__call__, arg) + + async def test_check_is_charm_removed__model_does_not_exist(self): + arg = CheckCharmIsRemovedImpl.Input( + application_name=self.application_name, + model_name="not-existing-model", + vim_uuid="vim-uuid", + poll_interval=0, + ) + self.controller.list_models.return_value = [namespace] + + await self.env.run(self.check_charm_is_removed.__call__, arg) + self.controller.get_model.assert_not_called()