diff options
author | Michael Hwang <mhwang@research.att.com> | 2017-09-12 17:28:37 -0400 |
---|---|---|
committer | Michael Hwang <mhwang@research.att.com> | 2017-09-12 17:30:38 -0400 |
commit | 9d0a254d0bcd6e966c47f2656527274ab1787d97 (patch) | |
tree | d13c8afc7d40087fa840ad0f537ec31a666df97e /docker/dockerplugin/decorators.py | |
parent | 9444408bb1ab548995a81d4efe678d298aca66df (diff) |
Combine all task inputs for create and start
Change-Id: Ia86d3b26b5ecccd636fb171b3967f924b0cb1250
Issue-Id: DCAEGEN2-91
Signed-off-by: Michael Hwang <mhwang@research.att.com>
Diffstat (limited to 'docker/dockerplugin/decorators.py')
-rw-r--r-- | docker/dockerplugin/decorators.py | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/docker/dockerplugin/decorators.py b/docker/dockerplugin/decorators.py index 089231a..f83263b 100644 --- a/docker/dockerplugin/decorators.py +++ b/docker/dockerplugin/decorators.py @@ -25,6 +25,7 @@ from dockering import utils as doc from dockerplugin import discovery as dis from dockerplugin.exceptions import DockerPluginDeploymentError, \ DockerPluginDependencyNotReadyError +from dockerplugin import utils def monkeypatch_loggers(task_func): @@ -62,19 +63,40 @@ def wrap_error_handling_start(task_start_func): return wrapper -def merge_inputs_for_start(task_start_func): +def _wrapper_merge_inputs(task_func, properties, **kwargs): + """Merge Cloudify properties with input kwargs before calling task func""" + inputs = copy.deepcopy(properties) + # Recursively update + utils.update_dict(inputs, kwargs) + + # Apparently kwargs contains "ctx" which is cloudify.context.CloudifyContext + # This has to be removed and not copied into runtime_properties else you get + # JSON serialization errors. + if "ctx" in inputs: + del inputs["ctx"] + + return task_func(**inputs) + +def merge_inputs_for_create(task_create_func): """Merge all inputs for start operation into one dict""" - def wrapper (**kwargs): - start_inputs = copy.deepcopy(ctx.instance.runtime_properties) - start_inputs.update(kwargs) + # Needed to wrap the wrapper because I was seeing issues with + # "RuntimeError: No context set in current execution thread" + def wrapper(**kwargs): + # NOTE: ctx.node.properties is an ImmutableProperties instance which is + # why it is passed into a mutable dict so that it can be deep copied + return _wrapper_merge_inputs(task_create_func, + dict(ctx.node.properties), **kwargs) + + return wrapper - # Apparently kwargs contains "ctx" which is cloudify.context.CloudifyContext - # This has to be removed and not copied into runtime_properties else you get - # JSON serialization errors. - if "ctx" in start_inputs: - del start_inputs["ctx"] +def merge_inputs_for_start(task_start_func): + """Merge all inputs for start operation into one dict""" - return task_start_func(**start_inputs) + # Needed to wrap the wrapper because I was seeing issues with + # "RuntimeError: No context set in current execution thread" + def wrapper(**kwargs): + return _wrapper_merge_inputs(task_start_func, + ctx.instance.runtime_properties, **kwargs) return wrapper |