StackStorm / st2

StackStorm (aka "IFTTT for Ops") is event-driven automation for auto-remediation, incident responses, troubleshooting, deployments, and more for DevOps and SREs. Includes rules engine, workflow, 160 integration packs with 6000+ actions (see https://exchange.stackstorm.org) and ChatOps. Installer at https://docs.stackstorm.com/install/index.html
https://stackstorm.com/
Apache License 2.0
6.08k stars 747 forks source link

Cannot evaluate Jinja expression when calling mistral in 2 consecutive action-chains #4475

Closed ncongtan closed 4 years ago

ncongtan commented 5 years ago
SUMMARY

Hi everyone, I have an issue about workflow mistral and action-chain. When I call mistral in 2 consecutive action-chains

testing1 (action-chains) > testing2 (action-chains)> testing3 (mistral)

It's failed with error [ Can not evaluate Jinja expression ]. Please help me, thanks very much.

{

"traceback": " File \"/opt/stackstorm/st2/lib/python2.7/site-packages/st2actions/container/base.py\", line 126, in _do_run\n (status, result, context) = runner.run(action_params)\n File \"/opt/stackstorm/st2/lib/python2.7/site-packages/retrying.py\", line 49, in wrapped_f\n return Retrying(*dargs, **dkw).call(f, *args, **kw)\n File \"/opt/stackstorm/st2/lib/python2.7/site-packages/retrying.py\", line 206, in call\n return attempt.get(self._wrap_exception)\n File \"/opt/stackstorm/st2/lib/python2.7/site-packages/retrying.py\", line 247, in get\n six.reraise(self.value[0], self.value[1], self.value[2])\n File \"/opt/stackstorm/st2/lib/python2.7/site-packages/retrying.py\", line 200, in call\n attempt = Attempt(fn(*args, **kwargs), attempt_number, False)\n File \"/opt/stackstorm/runners/mistral_v2/mistral_v2/mistral_v2.py\", line 247, in run\n result = self.start_workflow(action_parameters=action_parameters)\n File \"/opt/stackstorm/runners/mistral_v2/mistral_v2/mistral_v2.py\", line 289, in start_workflow\n **options)\n File \"/opt/stackstorm/st2/lib/python2.7/site-packages/mistralclient/api/v2/executions.py\", line 65, in create\n return self._create('/executions', data)\n File \"/opt/stackstorm/st2/lib/python2.7/site-packages/mistralclient/api/base.py\", line 100, in _create\n self._raise_api_exception(resp)\n File \"/opt/stackstorm/st2/lib/python2.7/site-packages/mistralclient/api/base.py\", line 160, in _raise_api_exception\n error_message=error_data)\n", "error": *"Can not evaluate Jinja expression [expression=username, error='username' is undefined,* data={'__env': {u'st2_liveaction_id': u'5c13a011e13823e5dea1ee6c', u'st2_execution_id': u'5c13a011e13823e5dea1ee6d', u'__actions': {u'st2.action': {u'st2_context': {u'endpoint': u'http://127.0.0.1:9101/v1/actionexecutions', u'api_url': u'http://127.0.0.1:9101/v1', u'parent': {u'parent': {u'execution_id': u'5c13a010e13823e5da3e0766', u'pack': u'quoit_common', u'chain': {u'name': u'task1', u'parameters': {u'username': u'{{username}}', u'gender': u'{{gender}}'}, u'publish': {u'processing_result': u\"{{'test_value'}}\"}, u'params': None, u'notify': None, u'on_failure': None, u'ref': u'quoit_common.testing2', u'on_success': None}, u'parent': {u'trace_context': {}, u'user': u'st2admin', u'execution_id': u'5c13a00fe13823e80dc0bded', u'pack': u'quoit_common'}, u'user': u'st2admin'}, u'user': u'st2admin', u'chain': {u'name': u'task1', u'parameters': {u'username': u'{% raw %}{{username}}{% endraw %}', u'gender': u'{% raw %}{{gender}}{% endraw %}'}, u'publish': {u'processing_result': u\"{{'test_value'}}\"}, u'params': None, u'notify': None, u'on_failure': None, *u'ref': u'quoit_common.testing3', u'on_success': None},* u'execution_id': u'5c13a011e13823e5dea1ee6d', u'pack': u'quoit_common'}, u'auth_token': u'7a82e3de2a7141b98f1fda824a07c750', u'skip_notify_tasks': [], u'notify': {}}}}, u'st2_action_api_url': u'http://127.0.0.1:9101/v1'}}]" }

Link refer: https://stackstorm-community.slack.com/archives/C066APT88/p1544789967918200

ISSUE TYPE
STACKSTORM VERSION

st2 2.9.1, on Python 2.7.15

OS / ENVIRONMENT / INSTALL METHOD

Operating System: CentOS Linux 7 (Core) Kernel: Linux 3.10.0-862.9.1.el7.x86_64 Architecture: x86-64

Installed via CLI https://docs.stackstorm.com/install/rhel7.html

STEPS TO REPRODUCE

This is my demo about mistral in 2 consecutive action-chains above:

File testing1.meta.yaml

---
name: "testing1"
description: "testing1"
runner_type: "action-chain"
entry_point: "chains/testing1.yaml"
enabled: true
parameters:
    username:
        type: "string"
        description: "username"
        required: true
    gender:
        type: "string"
        description: "gender"
        required: true

File testing1.yaml

---
    chain:
        -
            name: "task1"
            ref: "quoit_common.testing2"
            parameters:
                username: "{{username}}"
                gender: "{{gender}}"
            publish:
                processing_result: "{{'test_value'}}"
    default: "task1"

=================== File testing2.meta.yaml

---
name: "testing2"
description: "testing2 workflow"
runner_type: "action-chain"
entry_point: "chains/testing2.yaml"
enabled: true
parameters:
    username:
        type: "string"
        required: true
        description: "username"
    gender:
        type: "string"
        required: false
        description: "gender"

File testing2.yaml

---
    chain:
        -
            name: "task1"
            ref: "quoit_common.testing3"
            parameters:
                username: "{{username}}"
                gender: "{{gender}}"
            publish:
                processing_result: "{{'test_value'}}"
    default: "task1"

=================== File testing3.yaml

---
name: "testing3"
description: "testing3 mistral workflow"
runner_type: "mistral-v2"
entry_point: "workflows/testing3.yaml"
enabled: true
parameters:
    username:
        type: "string"
        required: false
        description: "username"
    gender:
        type: "string"
        required: false
        description: "gender"

File testing3.yaml

---
version: '2.0'

quoit_common.testing3:
    description: A basic workflow for testing3
    type: direct
    input:
        - username
        - gender
    output:
        processing_result: <% $.processing_result %>
    tasks:
        task1:
            action: quoit_common.run_actions
            input:
                username: <% $.username %>
                gender: <% $.gender %>
            publish:
                processing_result: <% 'test_value' %>

=================== File run_actions.yaml

---
name: "run_actions"
runner_type: "python-script"
description: "run_actions"
enabled: true
entry_point: "python_scripts/run_actions.py"
parameters:
    username:
        type: "string"
        description: "username"
        required: false
    gender:
        type: "string"
        description: "gender"
        required: false

File run_actions.py

#!/usr/bin/python

from st2common.runners.base_action import Action

class RunActions(Action):
    def run(self, username, gender):
        print ('username')
        print('gender')
EXPECTED RESULTS
ACTUAL RESULTS
arm4b commented 5 years ago

Thanks for taking time to write this report along with steps to reproduce.

Just for your information, as we're going to deprecate Mistral in future in favor of Orquesta workflow, we less likely to spend some time on Mistral improvements/fixes (unless it's something critical), being focused on new workflow engine development and feature parity between Mistral <> Orquesta.

I'd suggest to start your migration to Orquesta when possible: https://docs.stackstorm.com/orquesta/index.html and report bugs/feature requests about new workflow engine, if you find something missing.