StackStorm / StackStorm/st2

WebUI generates invalid rule YAML

Open
#3,386 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
6.5k
Forks
787
PR merge metrics
No merged PRs in 30d

Description

This was a follow-up to a user-reported issue in #community. The WebUI seems to be able to create rules just fine, but the YAML shown in the code pane doesn't appear to be a valid rule.

Here's a sample rule I created:

screen shot 2017-05-02 at 4 48 31 pm

I then pasted exactly the YAML shown in the "code" pane after creation into it's own rule file. I deleted the rule I created with the GUI, then executed an st2ctl reload so that the rule would get re-created with this YAML file, and ran into a parsing issue:

vagrant@st2vagrant:/opt/stackstorm/packs/core/rules$ cat test_rule.yaml
---
description: 'Turn on the site-to-site VPN'
tags: []
type:
  ref: standard
  parameters:
enabled: true
name: vpnOn
trigger:
  ref: core.4b855a3a-e01e-4149-a3b2-a379a39cdb07
  type: core.st2.webhook
  parameters:
    url: vpnOn
criteria:
action:
  ref: core.noop
  parameters:
pack: core
ref: core.vpnOn
id: 59091ad4c4da5f28167e0cbd
uid: 'rule:core:vpnOn'
vagrant@st2vagrant:/opt/stackstorm/packs/core/rules$ st2ctl reload
Registering content...[flags = --config-file /etc/st2/st2.conf --register-runners --register-actions --register-aliases --register-sensors --register-triggers --register-configs --register-rules]
2017-05-02 23:50:10,185 INFO [-] Connecting to database "st2" @ "0.0.0.0:27017" as user "stackstorm".
2017-05-02 23:50:10,296 INFO [-] =========================================================
2017-05-02 23:50:10,296 INFO [-] ############## Registering triggers #####################
2017-05-02 23:50:10,296 INFO [-] =========================================================
2017-05-02 23:50:10,499 INFO [-] Registered 1 triggers.
2017-05-02 23:50:10,500 INFO [-] =========================================================
2017-05-02 23:50:10,500 INFO [-] ############## Registering sensors ######################
2017-05-02 23:50:10,500 INFO [-] =========================================================
2017-05-02 23:50:10,670 INFO [-] Registered 5 sensors.
2017-05-02 23:50:10,670 INFO [-] =========================================================
2017-05-02 23:50:10,671 INFO [-] ############## Registering runners ######################
2017-05-02 23:50:10,671 INFO [-] =========================================================
2017-05-02 23:50:10,965 INFO [-] Registered 13 runners.
2017-05-02 23:50:10,966 INFO [-] =========================================================
2017-05-02 23:50:10,967 INFO [-] ############## Registering actions ######################
2017-05-02 23:50:10,967 INFO [-] =========================================================
2017-05-02 23:50:20,522 INFO [-] Registered 372 actions.
2017-05-02 23:50:20,523 INFO [-] =========================================================
2017-05-02 23:50:20,523 INFO [-] ############## Registering rules ########################
2017-05-02 23:50:20,524 INFO [-] =========================================================
2017-05-02 23:50:20,568 WARNING [-] Failed to register rules: Failed to register rule "/opt/stackstorm/packs/core/rules/test_rule.yaml" from pack "core": 'NoneType' object is not iterable
Traceback (most recent call last):
  File "/usr/bin/st2-register-content", line 22, in <module>
    sys.exit(content_loader.main(sys.argv[1:]))
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/content/bootstrap.py", line 387, in main
    register_content()
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/content/bootstrap.py", line 362, in register_content
    register_rules()
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/content/bootstrap.py", line 248, in register_rules
    raise e
ValueError: Failed to register rule "/opt/stackstorm/packs/core/rules/test_rule.yaml" from pack "core": 'NoneType' object is not iterable

The problem is that the criteria and action.parameters fields aren't followed by a {} if their values are empty. Adding these fixed it:

vagrant@st2vagrant:/opt/stackstorm/packs/core/rules$ cat test_rule.yaml
---
description: 'Turn on the site-to-site VPN'
tags: []
type:
  ref: standard
  parameters:
enabled: true
name: vpnOn
trigger:
  ref: core.4b855a3a-e01e-4149-a3b2-a379a39cdb07
  type: core.st2.webhook
  parameters:
    url: vpnOn
criteria: {}
action:
  ref: core.noop
  parameters: {}
pack: core
ref: core.vpnOn
id: 59091ad4c4da5f28167e0cbd
uid: 'rule:core:vpnOn'
vagrant@st2vagrant:/opt/stackstorm/packs/core/rules$ st2ctl reload
Registering content...[flags = --config-file /etc/st2/st2.conf --register-runners --register-actions --register-aliases --register-sensors --register-triggers --register-configs --register-rules]
2017-05-02 23:53:51,065 INFO [-] Connecting to database "st2" @ "0.0.0.0:27017" as user "stackstorm".
2017-05-02 23:53:51,181 INFO [-] =========================================================
2017-05-02 23:53:51,181 INFO [-] ############## Registering triggers #####################
2017-05-02 23:53:51,181 INFO [-] =========================================================
2017-05-02 23:53:51,425 INFO [-] Registered 1 triggers.
2017-05-02 23:53:51,426 INFO [-] =========================================================
2017-05-02 23:53:51,427 INFO [-] ############## Registering sensors ######################
2017-05-02 23:53:51,427 INFO [-] =========================================================
2017-05-02 23:53:51,729 INFO [-] Registered 5 sensors.
2017-05-02 23:53:51,730 INFO [-] =========================================================
2017-05-02 23:53:51,730 INFO [-] ############## Registering runners ######################
2017-05-02 23:53:51,731 INFO [-] =========================================================
2017-05-02 23:53:52,067 INFO [-] Registered 13 runners.
2017-05-02 23:53:52,068 INFO [-] =========================================================
2017-05-02 23:53:52,068 INFO [-] ############## Registering actions ######################
2017-05-02 23:53:52,069 INFO [-] =========================================================
2017-05-02 23:53:58,919 INFO [-] Registered 372 actions.
2017-05-02 23:53:58,920 INFO [-] =========================================================
2017-05-02 23:53:58,920 INFO [-] ############## Registering rules ########################
2017-05-02 23:53:58,921 INFO [-] =========================================================
2017-05-02 23:53:59,224 INFO [-] Registered 11 rules.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the WebUI code pane's rule YAML generation and compare the emitted output with the rule YAML shown in the issue. Reproduce with an empty criteria object and empty action parameters, then confirm that the generated YAML includes {} and succeeds when reloaded with st2ctl reload.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, yaml
Domain
full-stack
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.