SEBA-298 Pass parser to callback in threadsafe way
Change-Id: Ia7f04eca63e83d9deaab5758c47d3889aef582cf
diff --git a/src/grpc_client/main.py b/src/grpc_client/main.py
index 3633797..619b43b 100644
--- a/src/grpc_client/main.py
+++ b/src/grpc_client/main.py
@@ -35,13 +35,13 @@
self.grpc_secure_endpoint = secure + ":50051"
self.grpc_insecure_endpoint = insecure + ":50055"
- def setup_resources(self, client, key, deferred, recipe):
+ def setup_resources(self, client, key, deferred, arg):
log.info("[XOS-TOSCA] Loading resources for authenticated user")
if key not in RESOURCES:
RESOURCES[key] = {}
for k in client.xos_orm.all_model_names:
RESOURCES[key][k] = getattr(client.xos_orm, k)
- reactor.callLater(0, deferred.callback, recipe)
+ reactor.callLater(0, deferred.callback, arg)
def start(self):
log.info("[XOS-TOSCA] Connecting to xos-core")
@@ -60,14 +60,14 @@
return deferred
- def create_secure_client(self, username, password, recipe):
+ def create_secure_client(self, username, password, arg):
"""
This method will check if this combination of username/password already has stored orm classes in RESOURCES, otherwise create them
"""
deferred = defer.Deferred()
key = "%s~%s" % (username, password)
if key in RESOURCES:
- reactor.callLater(0, deferred.callback, recipe)
+ reactor.callLater(0, deferred.callback, arg)
else:
local_cert = Config.get('local_cert')
client = SecureClient(endpoint=self.grpc_secure_endpoint, username=username, password=password, cacert=local_cert)
@@ -75,6 +75,6 @@
# SecureClient is preceeded by an insecure client, so treat all secure clients as previously connected
# See CORD-3152
client.was_connected = True
- client.set_reconnect_callback(functools.partial(self.setup_resources, client, key, deferred, recipe))
+ client.set_reconnect_callback(functools.partial(self.setup_resources, client, key, deferred, arg))
client.start()
return deferred
diff --git a/src/web_server/main.py b/src/web_server/main.py
index 9a6c9b3..271b1b2 100644
--- a/src/web_server/main.py
+++ b/src/web_server/main.py
@@ -39,12 +39,12 @@
app = Klein()
- def execute_tosca(self, recipe):
- self.parser.execute()
- if self.parser.delete:
- response_text = "Deleted models: %s" % str(self.parser.ordered_models_name)
+ def execute_tosca(self, parser):
+ parser.execute()
+ if parser.delete:
+ response_text = "Deleted models: %s" % str(parser.ordered_models_name)
else:
- response_text = "Created models: %s" % str(self.parser.ordered_models_name)
+ response_text = "Created models: %s" % str(parser.ordered_models_name)
return response_text
def errorCallback(self, failure, request):
@@ -83,8 +83,8 @@
username = headers['xos-username']
password = headers['xos-password']
- d = GRPC_Client().create_secure_client(username, password, recipe)
- self.parser = TOSCA_Parser(recipe, username, password)
+ parser = TOSCA_Parser(recipe, username, password)
+ d = GRPC_Client().create_secure_client(username, password, parser)
tosca_execution = d.addCallback(self.execute_tosca)
tosca_execution.addErrback(self.errorCallback, request)
return d
@@ -96,8 +96,8 @@
username = headers['xos-username']
password = headers['xos-password']
- d = GRPC_Client().create_secure_client(username, password, recipe)
- self.parser = TOSCA_Parser(recipe, username, password, delete=True)
+ parser = TOSCA_Parser(recipe, username, password, delete=True)
+ d = GRPC_Client().create_secure_client(username, password, parser)
tosca_execution = d.addCallback(self.execute_tosca)
tosca_execution.addErrback(self.errorCallback, request)
return d