Fix bug 1018
[osm/N2VC.git] / n2vc / juju_observer.py
index 25c1c1f..e2f0470 100644 (file)
@@ -57,7 +57,7 @@ class JujuModelObserver(ModelObserver):
         except Exception as e:
             # no entity_id aatribute, try machine attribute
             entity_id = machine.machine
         except Exception as e:
             # no entity_id aatribute, try machine attribute
             entity_id = machine.machine
-        self.n2vc.debug(msg='Registering machine for changes notifications: {}'.format(entity_id))
+        # self.n2vc.debug(msg='Registering machine for change notifications: {}'.format(entity_id))
         entity = _Entity(entity_id=entity_id, entity_type='machine', obj=machine, db_dict=db_dict)
         self.machines[entity_id] = entity
 
         entity = _Entity(entity_id=entity_id, entity_type='machine', obj=machine, db_dict=db_dict)
         self.machines[entity_id] = entity
 
@@ -70,7 +70,7 @@ class JujuModelObserver(ModelObserver):
 
     def register_application(self, application: Application, db_dict: dict):
         entity_id = application.entity_id
 
     def register_application(self, application: Application, db_dict: dict):
         entity_id = application.entity_id
-        self.n2vc.debug(msg='Registering application for changes notifications: {}'.format(entity_id))
+        # self.n2vc.debug(msg='Registering application for change notifications: {}'.format(entity_id))
         entity = _Entity(entity_id=entity_id, entity_type='application', obj=application, db_dict=db_dict)
         self.applications[entity_id] = entity
 
         entity = _Entity(entity_id=entity_id, entity_type='application', obj=application, db_dict=db_dict)
         self.applications[entity_id] = entity
 
@@ -83,7 +83,7 @@ class JujuModelObserver(ModelObserver):
 
     def register_action(self, action: Action, db_dict: dict):
         entity_id = action.entity_id
 
     def register_action(self, action: Action, db_dict: dict):
         entity_id = action.entity_id
-        self.n2vc.debug(msg='Registering action for changes notifications: {}'.format(entity_id))
+        self.n2vc.debug(msg='Registering action for changes notifications: {}'.format(entity_id))
         entity = _Entity(entity_id=entity_id, entity_type='action', obj=action, db_dict=db_dict)
         self.actions[entity_id] = entity
 
         entity = _Entity(entity_id=entity_id, entity_type='action', obj=action, db_dict=db_dict)
         self.actions[entity_id] = entity
 
@@ -103,6 +103,8 @@ class JujuModelObserver(ModelObserver):
         if not self.is_machine_registered(machine_id):
             return
 
         if not self.is_machine_registered(machine_id):
             return
 
+        self.n2vc.debug('Waiting for machine completed: {}'.format(machine_id))
+
         # wait for a final state
         entity = self.machines[machine_id]
         return await self._wait_for_entity(
         # wait for a final state
         entity = self.machines[machine_id]
         return await self._wait_for_entity(
@@ -121,6 +123,8 @@ class JujuModelObserver(ModelObserver):
         if not self.is_application_registered(application_id):
             return
 
         if not self.is_application_registered(application_id):
             return
 
+        self.n2vc.debug('Waiting for application completed: {}'.format(application_id))
+
         # application statuses: unknown, active, waiting
         # wait for a final state
         entity = self.applications[application_id]
         # application statuses: unknown, active, waiting
         # wait for a final state
         entity = self.applications[application_id]
@@ -140,6 +144,8 @@ class JujuModelObserver(ModelObserver):
         if not self.is_action_registered(action_id):
             return
 
         if not self.is_action_registered(action_id):
             return
 
+        self.n2vc.debug('Waiting for action completed: {}'.format(action_id))
+
         # action statuses: pending, running, completed, failed, cancelled
         # wait for a final state
         entity = self.actions[action_id]
         # action statuses: pending, running, completed, failed, cancelled
         # wait for a final state
         entity = self.actions[action_id]
@@ -193,8 +199,8 @@ class JujuModelObserver(ModelObserver):
                     .format(progress_timeout, entity.entity_type, entity.entity_id)
                 self.n2vc.debug(message)
                 raise N2VCTimeoutException(message=message, timeout='progress')
                     .format(progress_timeout, entity.entity_type, entity.entity_id)
                 self.n2vc.debug(message)
                 raise N2VCTimeoutException(message=message, timeout='progress')
-        self.n2vc.debug('End of wait. Final state: {}, retries: {}'
-                        .format(entity.obj.__getattribute__(field_to_check), retries))
+        self.n2vc.debug('End of wait. Final state: {}, retries: {}'
+                        .format(entity.obj.__getattribute__(field_to_check), retries))
         return retries
 
     async def on_change(self, delta, old, new, model):
         return retries
 
     async def on_change(self, delta, old, new, model):
@@ -203,8 +209,8 @@ class JujuModelObserver(ModelObserver):
             return
 
         # log
             return
 
         # log
-        self.n2vc.debug('on_change(): type: {}, entity: {}, id: {}'
-                        .format(delta.type, delta.entity, new.entity_id))
+        self.n2vc.debug('on_change(): type: {}, entity: {}, id: {}'
+                        .format(delta.type, delta.entity, new.entity_id))
 
         if delta.entity == 'machine':
 
 
         if delta.entity == 'machine':
 
@@ -252,13 +258,14 @@ class JujuModelObserver(ModelObserver):
                 return
 
             # write change in database
                 return
 
             # write change in database
-            await self.n2vc.write_app_status_to_db(
-                db_dict=self.applications[application_id].db_dict,
-                status=juju_status_2_osm_status(delta.entity, new.workload_status),
-                detailed_status=new.workload_status_message,
-                vca_status=new.workload_status,
-                entity_type='unit'
-            )
+            if not new.dead:
+                await self.n2vc.write_app_status_to_db(
+                    db_dict=self.applications[application_id].db_dict,
+                    status=juju_status_2_osm_status(delta.entity, new.workload_status),
+                    detailed_status=new.workload_status_message,
+                    vca_status=new.workload_status,
+                    entity_type='unit'
+                )
 
             # set event for this application
             self.applications[application_id].event.set()
 
             # set event for this application
             self.applications[application_id].event.set()