{"action":"opened","issue":{"url":"https://api.github.com/repos/StackStorm/st2/issues/3386","repository_url":"https://api.github.com/repos/StackStorm/st2","labels_url":"https://api.github.com/repos/StackStorm/st2/issues/3386/labels{/name}","comments_url":"https://api.github.com/repos/StackStorm/st2/issues/3386/comments","events_url":"https://api.github.com/repos/StackStorm/st2/issues/3386/events","html_url":"https://github.com/StackStorm/st2/issues/3386","id":225854003,"number":3386,"title":"WebUI generates invalid rule YAML","user":{"login":"Mierdin","id":4230395,"avatar_url":"https://avatars3.githubusercontent.com/u/4230395?v=3","gravatar_id":"","url":"https://api.github.com/users/Mierdin","html_url":"https://github.com/Mierdin","followers_url":"https://api.github.com/users/Mierdin/followers","following_url":"https://api.github.com/users/Mierdin/following{/other_user}","gists_url":"https://api.github.com/users/Mierdin/gists{/gist_id}","starred_url":"https://api.github.com/users/Mierdin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mierdin/subscriptions","organizations_url":"https://api.github.com/users/Mierdin/orgs","repos_url":"https://api.github.com/users/Mierdin/repos","events_url":"https://api.github.com/users/Mierdin/events{/privacy}","received_events_url":"https://api.github.com/users/Mierdin/received_events","type":"User","site_admin":false},"labels":[{"id":94405702,"url":"https://api.github.com/repos/StackStorm/st2/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-05-02T23:57:35Z","updated_at":"2017-05-02T23:57:35Z","closed_at":null,"body":"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.\r\n\r\nHere's a sample rule I created:\r\n\r\n![screen shot 2017-05-02 at 4 48 31 pm](https://cloud.githubusercontent.com/assets/4230395/25643950/8cb7bd48-2f57-11e7-93aa-0494e80993ae.png)\r\n\r\nI 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:\r\n\r\n```\r\nvagrant@st2vagrant:/opt/stackstorm/packs/core/rules$ cat test_rule.yaml\r\n---\r\ndescription: 'Turn on the site-to-site VPN'\r\ntags: []\r\ntype:\r\n  ref: standard\r\n  parameters:\r\nenabled: true\r\nname: vpnOn\r\ntrigger:\r\n  ref: core.4b855a3a-e01e-4149-a3b2-a379a39cdb07\r\n  type: core.st2.webhook\r\n  parameters:\r\n    url: vpnOn\r\ncriteria:\r\naction:\r\n  ref: core.noop\r\n  parameters:\r\npack: core\r\nref: core.vpnOn\r\nid: 59091ad4c4da5f28167e0cbd\r\nuid: 'rule:core:vpnOn'\r\nvagrant@st2vagrant:/opt/stackstorm/packs/core/rules$ st2ctl reload\r\nRegistering content...[flags = --config-file /etc/st2/st2.conf --register-runners --register-actions --register-aliases --register-sensors --register-triggers --register-configs --register-rules]\r\n2017-05-02 23:50:10,185 INFO [-] Connecting to database \"st2\" @ \"0.0.0.0:27017\" as user \"stackstorm\".\r\n2017-05-02 23:50:10,296 INFO [-] =========================================================\r\n2017-05-02 23:50:10,296 INFO [-] ############## Registering triggers #####################\r\n2017-05-02 23:50:10,296 INFO [-] =========================================================\r\n2017-05-02 23:50:10,499 INFO [-] Registered 1 triggers.\r\n2017-05-02 23:50:10,500 INFO [-] =========================================================\r\n2017-05-02 23:50:10,500 INFO [-] ############## Registering sensors ######################\r\n2017-05-02 23:50:10,500 INFO [-] =========================================================\r\n2017-05-02 23:50:10,670 INFO [-] Registered 5 sensors.\r\n2017-05-02 23:50:10,670 INFO [-] =========================================================\r\n2017-05-02 23:50:10,671 INFO [-] ############## Registering runners ######################\r\n2017-05-02 23:50:10,671 INFO [-] =========================================================\r\n2017-05-02 23:50:10,965 INFO [-] Registered 13 runners.\r\n2017-05-02 23:50:10,966 INFO [-] =========================================================\r\n2017-05-02 23:50:10,967 INFO [-] ############## Registering actions ######################\r\n2017-05-02 23:50:10,967 INFO [-] =========================================================\r\n2017-05-02 23:50:20,522 INFO [-] Registered 372 actions.\r\n2017-05-02 23:50:20,523 INFO [-] =========================================================\r\n2017-05-02 23:50:20,523 INFO [-] ############## Registering rules ########################\r\n2017-05-02 23:50:20,524 INFO [-] =========================================================\r\n2017-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\r\nTraceback (most recent call last):\r\n  File \"/usr/bin/st2-register-content\", line 22, in <module>\r\n    sys.exit(content_loader.main(sys.argv[1:]))\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/content/bootstrap.py\", line 387, in main\r\n    register_content()\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/content/bootstrap.py\", line 362, in register_content\r\n    register_rules()\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/content/bootstrap.py\", line 248, in register_rules\r\n    raise e\r\nValueError: Failed to register rule \"/opt/stackstorm/packs/core/rules/test_rule.yaml\" from pack \"core\": 'NoneType' object is not iterable\r\n```\r\n\r\nThe problem is that the `criteria` and `action.parameters` fields aren't followed by a `{}` if their values are empty. Adding these fixed it:\r\n\r\n```\r\nvagrant@st2vagrant:/opt/stackstorm/packs/core/rules$ cat test_rule.yaml\r\n---\r\ndescription: 'Turn on the site-to-site VPN'\r\ntags: []\r\ntype:\r\n  ref: standard\r\n  parameters:\r\nenabled: true\r\nname: vpnOn\r\ntrigger:\r\n  ref: core.4b855a3a-e01e-4149-a3b2-a379a39cdb07\r\n  type: core.st2.webhook\r\n  parameters:\r\n    url: vpnOn\r\ncriteria: {}\r\naction:\r\n  ref: core.noop\r\n  parameters: {}\r\npack: core\r\nref: core.vpnOn\r\nid: 59091ad4c4da5f28167e0cbd\r\nuid: 'rule:core:vpnOn'\r\nvagrant@st2vagrant:/opt/stackstorm/packs/core/rules$ st2ctl reload\r\nRegistering content...[flags = --config-file /etc/st2/st2.conf --register-runners --register-actions --register-aliases --register-sensors --register-triggers --register-configs --register-rules]\r\n2017-05-02 23:53:51,065 INFO [-] Connecting to database \"st2\" @ \"0.0.0.0:27017\" as user \"stackstorm\".\r\n2017-05-02 23:53:51,181 INFO [-] =========================================================\r\n2017-05-02 23:53:51,181 INFO [-] ############## Registering triggers #####################\r\n2017-05-02 23:53:51,181 INFO [-] =========================================================\r\n2017-05-02 23:53:51,425 INFO [-] Registered 1 triggers.\r\n2017-05-02 23:53:51,426 INFO [-] =========================================================\r\n2017-05-02 23:53:51,427 INFO [-] ############## Registering sensors ######################\r\n2017-05-02 23:53:51,427 INFO [-] =========================================================\r\n2017-05-02 23:53:51,729 INFO [-] Registered 5 sensors.\r\n2017-05-02 23:53:51,730 INFO [-] =========================================================\r\n2017-05-02 23:53:51,730 INFO [-] ############## Registering runners ######################\r\n2017-05-02 23:53:51,731 INFO [-] =========================================================\r\n2017-05-02 23:53:52,067 INFO [-] Registered 13 runners.\r\n2017-05-02 23:53:52,068 INFO [-] =========================================================\r\n2017-05-02 23:53:52,068 INFO [-] ############## Registering actions ######################\r\n2017-05-02 23:53:52,069 INFO [-] =========================================================\r\n2017-05-02 23:53:58,919 INFO [-] Registered 372 actions.\r\n2017-05-02 23:53:58,920 INFO [-] =========================================================\r\n2017-05-02 23:53:58,920 INFO [-] ############## Registering rules ########################\r\n2017-05-02 23:53:58,921 INFO [-] =========================================================\r\n2017-05-02 23:53:59,224 INFO [-] Registered 11 rules.\r\n```\r\n\r\n"}}
{"actor":{"display_login":"Mierdin"}}