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
block_until_done=False,
force=force_remove,
no_wait=force_remove,
+ destroy_storage=True,
)
@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
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,
block_until_done=False,
force=is_forced,
no_wait=is_forced,
+ destroy_storage=True,
)
async def test_remove_charm__app_does_not_exist(self):
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"],
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(
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, {}]
)
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()