Fix model deletion
[osm/N2VC.git] / 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
 
             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:
             # 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]
         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()
                 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))
 
         else:
             self.log.debug("Machine not found: {}".format(machine_id))