Fix machine deletion when delete execution environment 51/8651/3
authorcalvinosanch <guillermo.calvinosanchez@altran.com>
Fri, 21 Feb 2020 08:25:21 +0000 (09:25 +0100)
committerisraelad <adam.israel@canonical.com>
Thu, 27 Feb 2020 16:13:14 +0000 (17:13 +0100)
Change-Id: If389f267e996af3b93ef0ba59444733ab4c7ed7e
Signed-off-by: calvinosanch <guillermo.calvinosanchez@altran.com>
(cherry picked from commit 413952226163141c8f88c6c1b1eab419a7aad244)

n2vc/n2vc_juju_conn.py

index 4f0ee37..c6c9890 100644 (file)
@@ -585,15 +585,15 @@ class N2VCJujuConnector(N2VCConnector):
                                 .format(ee_id, application_name, e))
 
         # destroy the machine
-        try:
-            await self._juju_destroy_machine(
-                model_name=model_name,
-                machine_id=machine_id,
-                total_timeout=total_timeout
-            )
-        except Exception as e:
-            raise N2VCException(message='Error deleting execution environment {} (machine {}) : {}'
-                                .format(ee_id, machine_id, e))
+        # try: 
+            await self._juju_destroy_machine(
+                model_name=model_name,
+                machine_id=machine_id,
+                total_timeout=total_timeout
+            )
+        except Exception as e:
+            raise N2VCException(message='Error deleting execution environment {} (machine {}) : {}'
+                                .format(ee_id, machine_id, e))
 
         self.log.info('Execution environment {} deleted'.format(ee_id))
 
@@ -1223,9 +1223,11 @@ class N2VCJujuConnector(N2VCConnector):
 
         # get juju model and observer
         model = await self._juju_get_model(model_name=model_name)
+        observer = self.juju_observers[model_name]
 
         application = model.applications.get(application_name)
         if application:
+            observer.unregister_application(application_name)
             await application.destroy()
         else:
             self.log.debug('Application not found: {}'.format(application_name))
@@ -1244,10 +1246,12 @@ class N2VCJujuConnector(N2VCConnector):
 
         # get juju model and observer
         model = await self._juju_get_model(model_name=model_name)
+        observer = self.juju_observers[model_name]
 
         machines = await model.get_machines()
         if machine_id in machines:
             machine = model.machines[machine_id]
+            observer.unregister_machine(machine_id)
             await machine.destroy(force=True)
             # max timeout
             end = time.time() + total_timeout