Fix handling of user-scope datastore values inside action chain
workflows (previously they didn't work).
@@ -22,6 +22,7 @@ import datetime
import six
from jsonschema import exceptions as json_schema_exc
+from oslo_config import cfg
from st2common.runners.base import ActionRunner
from st2common.runners.base import get_metadata as get_runner_metadata
@@ -83,10 +84,11 @@ class ChainHolder(object):
self.vars = {}
- def init_vars(self, action_parameters):
+ def init_vars(self, action_parameters, action_context=None):
if self.actionchain.vars:
self.vars = self._get_rendered_vars(self.actionchain.vars,
- action_parameters=action_parameters)
+ action_parameters=action_parameters,
+ action_context=action_context)
def restore_vars(self, ctx_vars):
self.vars.update(fast_deepcopy(ctx_vars))
@@ -203,14 +205,20 @@ class ChainHolder(object):
return node_name in all_node_names
@staticmethod
- def _get_rendered_vars(vars, action_parameters):
+ def _get_rendered_vars(vars, action_parameters, action_context):
if not vars:
return {}
+
+ action_context = action_context or {}
+ user = action_context.get('user', cfg.CONF.system_user.user)
+
context = {}
context.update({
kv_constants.DATASTORE_PARENT_SCOPE: {
kv_constants.SYSTEM_SCOPE: kv_service.KeyValueLookup(
- scope=kv_constants.FULL_SYSTEM_SCOPE)
+ scope=kv_constants.FULL_SYSTEM_SCOPE),
+ kv_constants.USER_SCOPE: kv_service.UserKeyValueLookup(
+ scope=kv_constants.FULL_USER_SCOPE, user=user)
}
})
context.update(action_parameters)
@@ -376,7 +384,8 @@ class ActionChainRunner(ActionRunner):
try:
# Initialize vars with the action parameters.
# This allows action parameers to be referenced from vars.
- self.chain_holder.init_vars(action_parameters)
+ self.chain_holder.init_vars(action_parameters=action_parameters,
+ action_context=self.context)
except Exception as e:
chain_status = action_constants.LIVEACTION_STATUS_FAILED
m = 'Failed initializing ``vars`` in chain.'
