X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Fvnf.py;h=8064cb3489680501d918c3a8dd5dbcecebc87e04;hp=df3ec00f06bb4fb86427f0b90e6b4acefc7f9431;hb=fc511ed0e2f3bbbdc0ccaa6b0d6ae7cc57b029f9;hpb=5e08a0e8fa4fd9d0156d28f8f4e53e5b176c704a diff --git a/n2vc/vnf.py b/n2vc/vnf.py index df3ec00..8064cb3 100644 --- a/n2vc/vnf.py +++ b/n2vc/vnf.py @@ -87,20 +87,14 @@ class VCAMonitor(ModelObserver): self.applications[application_name]['callback_args'] if old and new: - old_status = old.workload_status - new_status = new.workload_status - - if old_status == new_status: - """The workload status may fluctuate around certain - events, so wait until the status has stabilized before - triggering the callback.""" - if callback: - callback( - self.ns_name, - delta.data['application'], - new_status, - new.workload_status_message, - *callback_args) + # Fire off a callback with the application state + if callback: + callback( + self.ns_name, + delta.data['application'], + new.workload_status, + new.workload_status_message, + *callback_args) if old and not new: # This is a charm being removed @@ -173,6 +167,12 @@ class N2VC: self.connecting = False self.authenticated = False + # For debugging + self.refcount = { + 'controller': 0, + 'model': 0, + } + self.models = {} self.default_model = None @@ -811,6 +811,7 @@ class N2VC: self.models[model_name] = await self.controller.get_model( model_name, ) + self.refcount['model'] += 1 # Create an observer for this model self.monitors[model_name] = VCAMonitor(model_name) @@ -846,6 +847,7 @@ class N2VC: password=self.secret, cacert=cacert, ) + self.refcount['controller'] += 1 else: # current_controller no longer exists # self.log.debug("Connecting to current controller...") @@ -860,8 +862,6 @@ class N2VC: self.authenticated = True self.log.debug("JujuApi: Logged into controller") - # self.default_model = await self.controller.get_model("default") - async def logout(self): """Logout of the Juju controller.""" if not self.authenticated: @@ -873,20 +873,26 @@ class N2VC: self.default_model )) await self.default_model.disconnect() + self.refcount['model'] -= 1 self.default_model = None for model in self.models: await self.models[model].disconnect() - model = None + self.refcount['model'] -= 1 + self.models[model] = None if self.controller: self.log.debug("Disconnecting controller {}".format( self.controller )) await self.controller.disconnect() + self.refcount['controller'] -= 1 self.controller = None self.authenticated = False + + self.log.debug(self.refcount) + except Exception as e: self.log.fatal( "Fatal error logging out of Juju Controller: {}".format(e)