Fix model deletion 82/9182/6
authorDavid Garcia <david.garcia@canonical.com>
Thu, 25 Jun 2020 15:18:31 +0000 (17:18 +0200)
committergarciadav <david.garcia@canonical.com>
Tue, 30 Jun 2020 06:12:40 +0000 (08:12 +0200)
- Model deletion is failing with Juju 2.8

Change-Id: I6d7fc85ac9166a4eb7ff5851c231490400d64787
Signed-off-by: David Garcia <david.garcia@canonical.com>
n2vc/libjuju.py

index aa8a355..daedc3b 100644 (file)
@@ -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))