From fedac578fd86ff66055750fecc18c388d9390ebc Mon Sep 17 00:00:00 2001 From: David Garcia Date: Thu, 25 Jun 2020 17:18:31 +0200 Subject: [PATCH] Fix model deletion - Model deletion is failing with Juju 2.8 Change-Id: I6d7fc85ac9166a4eb7ff5851c231490400d64787 Signed-off-by: David Garcia (cherry picked from commit b8ff39bee1fffc09564f911ab522269306163f84) --- n2vc/libjuju.py | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py index aa8a355..daedc3b 100644 --- a/n2vc/libjuju.py +++ b/n2vc/libjuju.py @@ -737,19 +737,6 @@ class Libjuju: self.log.debug("Destroying model {}".format(model_name)) uuid = model.info.uuid - # Destroy applications - for application_name in model.applications: - try: - await self.destroy_application( - model, application_name=application_name, - ) - except Exception as e: - self.log.error( - "Error destroying application {} in model {}: {}".format( - application_name, model_name, e - ) - ) - # Destroy machines machines = await model.get_machines() for machine_id in machines: @@ -830,25 +817,19 @@ class Libjuju: machines = await model.get_machines() if machine_id in machines: machine = model.machines[machine_id] - # TODO: change this by machine.is_manual when this is upstreamed: - # https://github.com/juju/python-libjuju/pull/396 - if "instance-id" in machine.safe_data and machine.safe_data[ - "instance-id" - ].startswith("manual:"): - await machine.destroy(force=True) - - # max timeout - end = time.time() + total_timeout + await machine.destroy(force=True) + # max timeout + end = time.time() + total_timeout - # wait for machine removal + # wait for machine removal + machines = await model.get_machines() + while machine_id in machines and time.time() < end: + self.log.debug( + "Waiting for machine {} is destroyed".format(machine_id) + ) + await asyncio.sleep(0.5) machines = await model.get_machines() - while machine_id in machines and time.time() < end: - self.log.debug( - "Waiting for machine {} is destroyed".format(machine_id) - ) - await asyncio.sleep(0.5) - machines = await model.get_machines() - self.log.debug("Machine destroyed: {}".format(machine_id)) + self.log.debug("Machine destroyed: {}".format(machine_id)) else: self.log.debug("Machine not found: {}".format(machine_id)) -- 2.17.1