From: Adam Israel Date: Mon, 29 Apr 2019 18:59:45 +0000 (-0400) Subject: Fix bug 680 X-Git-Tag: v6.0.0~9 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F36%2F7436%2F4;p=osm%2FN2VC.git Fix bug 680 This patch adds two new methods, Subscribe and Unsubscribe, allowing the caller to subscribe to callback messages for an already deployed charm. Change-Id: I1e34b488914feb488cf80b157fd664ca37037e76 Signed-off-by: Adam Israel --- diff --git a/Makefile b/Makefile index abc2c39..fab6991 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ clean: find . -name *.pyc -delete rm -rf .tox rm -rf tests/charms/builds/* + lxc list test- --format=json|jq '.[]["name"]'| xargs lxc delete --force .tox: tox -r --notest test: lint diff --git a/n2vc/vnf.py b/n2vc/vnf.py index 9f8360b..a68e657 100644 --- a/n2vc/vnf.py +++ b/n2vc/vnf.py @@ -443,11 +443,10 @@ class N2VC: # Register this application with the model-level event monitor # ################################################################ if callback: - self.monitors[model_name].AddApplication( + self.log.debug("JujuApi: Registering callback for {}".format( application_name, - callback, - *callback_args - ) + )) + await self.Subscribe(model_name, application_name, callback, *callback_args) ######################################################## # Check for specific machine placement (native charms) # @@ -801,7 +800,7 @@ class N2VC: app = await self.get_application(model, application_name) if app: # Remove this application from event monitoring - self.monitors[model_name].RemoveApplication(application_name) + await self.Unsubscribe(model_name, application_name) # self.notify_callback(model_name, application_name, "removing", callback, *callback_args) self.log.debug( @@ -906,6 +905,33 @@ class N2VC: return True return False + async def Subscribe(self, ns_name, application_name, callback, *callback_args): + """Subscribe to callbacks for an application. + + :param ns_name str: The name of the Network Service + :param application_name str: The name of the application + :param callback obj: The callback method + :param callback_args list: The list of arguments to append to calls to + the callback method + """ + self.monitors[ns_name].AddApplication( + application_name, + callback, + *callback_args + ) + + async def Unsubscribe(self, ns_name, application_name): + """Unsubscribe to callbacks for an application. + + Unsubscribes the caller from notifications from a deployed application. + + :param ns_name str: The name of the Network Service + :param application_name str: The name of the application + """ + self.monitors[ns_name].RemoveApplication( + application_name, + ) + # Non-public methods async def add_relation(self, model_name, relation1, relation2): """