X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Fjuju_observer.py;h=e2f0470c5c1777240afb48aa7784f2ed701ff508;hp=ac40f34dcb122b43ed0de5580fdd7daefb25ee24;hb=8ff11999e2208889498a88be5db07b2861541cbd;hpb=2d413435b8530cf7b2c8e49cf8cf157679e72432;ds=sidebyside diff --git a/n2vc/juju_observer.py b/n2vc/juju_observer.py index ac40f34..e2f0470 100644 --- a/n2vc/juju_observer.py +++ b/n2vc/juju_observer.py @@ -52,7 +52,12 @@ class JujuModelObserver(ModelObserver): self.actions = dict() def register_machine(self, machine: Machine, db_dict: dict): - entity_id = machine.entity_id + try: + entity_id = machine.entity_id + except Exception as e: + # no entity_id aatribute, try machine attribute + entity_id = machine.machine + # 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 @@ -65,6 +70,7 @@ class JujuModelObserver(ModelObserver): def register_application(self, application: Application, db_dict: dict): entity_id = application.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 @@ -77,6 +83,7 @@ class JujuModelObserver(ModelObserver): 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)) entity = _Entity(entity_id=entity_id, entity_type='action', obj=action, db_dict=db_dict) self.actions[entity_id] = entity @@ -96,6 +103,8 @@ class JujuModelObserver(ModelObserver): 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( @@ -114,6 +123,8 @@ class JujuModelObserver(ModelObserver): 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] @@ -133,6 +144,8 @@ class JujuModelObserver(ModelObserver): 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] @@ -186,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') - 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): @@ -196,8 +209,8 @@ class JujuModelObserver(ModelObserver): 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': @@ -245,13 +258,14 @@ class JujuModelObserver(ModelObserver): 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()