From 168bb198ea5c86aaa2cd8d0e20c634ac896e385f Mon Sep 17 00:00:00 2001 From: David Garcia Date: Wed, 21 Oct 2020 14:19:45 +0200 Subject: [PATCH] Fix bug 1267: Destroy machines that are pending When osm destroys a NS, and a native charm hasn't been able to finish the provisioning of a machine, it will be in a pending state. As it was seen in the bug 1267, when a model is destroyed and machines are pending, the deletion of the model will get stuck. This patch solves that by checking (before deleting the model) if there are any manually provisioned machines in the juju model (native charms) in a pending state. If there are, it will destroy them so that the deletion of the model won't get stuck. Change-Id: Ia3f6ae7390ccc2bb5d4874d7d08fd446019b0901 Signed-off-by: David Garcia --- n2vc/libjuju.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py index a457309..8d1fdad 100644 --- a/n2vc/libjuju.py +++ b/n2vc/libjuju.py @@ -817,6 +817,10 @@ class Libjuju: self.log.debug("Destroying model {}".format(model_name)) uuid = model.info.uuid + # Destroy machines that are manually provisioned + # and still are in pending state + await self._destroy_pending_machines(model, only_manual=True) + # Disconnect model await self.disconnect_model(model) @@ -864,6 +868,23 @@ class Libjuju: else: self.log.warning("Application not found: {}".format(application_name)) + async def _destroy_pending_machines(self, model: Model, only_manual: bool = False): + """ + Destroy pending machines in a given model + + :param: only_manual: Bool that indicates only manually provisioned + machines should be destroyed (if True), or that + all pending machines should be destroyed + """ + status = await model.get_status() + for machine_id in status.machines: + machine_status = status.machines[machine_id] + if machine_status.agent_status.status == "pending": + if only_manual and not machine_status.instance_id.startswith("manual:"): + break + machine = model.machines[machine_id] + await machine.destroy(force=True) + # async def destroy_machine( # self, model: Model, machine_id: str, total_timeout: float = 3600 # ): -- 2.17.1