How to referencing an array type Key-Value Pairs in Action Definitions


(qinhao) #1

When i try to referencing an array type key-value pairs in action definitions

An error comes:

  File \"/opt/stackstorm/runners/action_chain_runner/action_chain_runner/action_chain_runner.py\", line 516, in _run_chain
    liveaction = self._run_action(liveaction)
  File \"/opt/stackstorm/runners/action_chain_runner/action_chain_runner/action_chain_runner.py\", line 734, in _run_action
    raise e
ValidationError: u'{{ st2kv.system.chatops_user_whitelist }}' is not of type u'array'
Failed validating u'type' in schema['properties'][u'whitelist']:
    {u'default': u'{{ st2kv.system.chatops_user_whitelist }}',
     u'type': u'array'}

On instance[u'whitelist']:
    u'{{ st2kv.system.chatops_user_whitelist }}'",
        "error": "Failed running task \"msg_prehandler\".. u'{{ st2kv.system.chatops_user_whitelist }}' is not of type u'array'

Failed validating u'type' in schema['properties'][u'whitelist']:
    {u'default': u'{{ st2kv.system.chatops_user_whitelist }}',
     u'type': u'array'}

On instance[u'whitelist']:
    u'{{ st2kv.system.chatops_user_whitelist }}'"

the definition of the action as below

whitelist:
  type: array
  default: "{{ st2kv.system.chatops_user_whitelist }}"

here is the key list

| name                   | value                        | secret | encrypted | scope        | user | expire_timestamp |
+------------------------+------------------------------+--------+-----------+--------------+------+------------------+
| chatops_user_blacklist | []                           | False  | False     | st2kv.system |      |                  |
| chatops_user_whitelist | ["q002723","w0102a","z0316"] | False  | False     | st2kv.system |      |                  |

(Lindsay Hill) #2

What version are you using, and how are you storing your values?

I just did this test:

$ st2 key set alpha_list '["a", "c", "b", "d"]'
$ st2 key get alpha_list
+------------------+----------------------+
| Property         | Value                |
+------------------+----------------------+
| name             | alpha_list           |
| value            | ["a", "c", "b", "d"] |
| secret           | False                |
| encrypted        | False                |
| scope            | st2kv.system         |
| expire_timestamp |                      |
+------------------+----------------------+
$

I set up this workflow:

---
name: echo
pack: default
description: echo input array
enabled: true
runner_type: mistral-v2
entry_point: workflows/echo.yaml
parameters:
  myvars:
    items:
      type: string
    minItems: 1
    type: array
    description: array of values to echo
    default: "{{ st2kv.system.alpha_list }}"
    position: 0
version: '2.0'
default.echo:
    description: echo various inputs
    type: direct
    input:
        - myvars
    tasks:
      echo_value:
        with-items:
          - blah in <% $.myvars %>
        action: core.local
        input:
          cmd: echo <% $.blah %>

And this worked as expected:

$ st2 run default.echo
..
id: 5b91fbcd99c96b3dc13434fd
action.ref: default.echo
parameters:
  myvars:
  - a
  - c
  - b
  - d
status: succeeded
result_task: echo_value
result: - failed: false
  return_code: 0
  stderr: ''
  stdout: a
  succeeded: true
- failed: false
  return_code: 0
  stderr: ''
  stdout: c
  succeeded: true
- failed: false
  return_code: 0
  stderr: ''
  stdout: b
  succeeded: true
- failed: false
  return_code: 0
  stderr: ''
  stdout: d
  succeeded: true
start_timestamp: Fri, 07 Sep 2018 04:17:17 UTC
end_timestamp: Fri, 07 Sep 2018 04:17:21 UTC
+--------------------------+------------------------+------------+------------+--------------------------+
| id                       | status                 | task       | action     | start_timestamp          |
+--------------------------+------------------------+------------+------------+--------------------------+
| 5b91fbce99c96b3dc1343500 | succeeded (1s elapsed) | echo_value | core.local | Fri, 07 Sep 2018         |
|                          |                        |            |            | 04:17:18 UTC             |
| 5b91fbce99c96b3dc1343502 | succeeded (1s elapsed) | echo_value | core.local | Fri, 07 Sep 2018         |
|                          |                        |            |            | 04:17:18 UTC             |
| 5b91fbce99c96b3dc1343504 | succeeded (1s elapsed) | echo_value | core.local | Fri, 07 Sep 2018         |
|                          |                        |            |            | 04:17:18 UTC             |
| 5b91fbcf99c96b3dc1343506 | succeeded (1s elapsed) | echo_value | core.local | Fri, 07 Sep 2018         |
|                          |                        |            |            | 04:17:18 UTC             |
+--------------------------+------------------------+------------+------------+--------------------------+

(qinhao) #3

Thank you for your reply. The problem is solved.

It turn out i have to refrence the key-value pair in the workflow definition yaml file then pass to the action, not just refrence in the action yaml.