Skip to content

Commit

Permalink
Merge pull request StackStorm#3177 from StackStorm/mistral-jinja-tests
Browse files Browse the repository at this point in the history
Add integration test for jinja evaluation in mistral
  • Loading branch information
m4dcoder authored Feb 2, 2017
2 parents 34f3237 + 9f43d98 commit 0b1d4e4
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ in development
cause a type mismatch in the API (bug fix)
* Use the newly introduced CANCELLED state in mistral for workflow cancellation. Currently, st2
put the workflow in a PAUSED state in mistral. (improvement)
* Add support for evaluating jinja expressions in mistral workflow definition where yaql
expressions are typically accepted. (improvement)

2.1.1 - December 16, 2016
-------------------------
Expand Down
21 changes: 21 additions & 0 deletions contrib/examples/actions/mistral-jinja-workbook-complex.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
description: Run a series of simulated actions.
enabled: true
entry_point: workflows/mistral-jinja-workbook-complex.yaml
name: mistral-jinja-workbook-complex
pack: examples
parameters:
cpu_cores:
default: 1
type: integer
memory_mb:
default: 1024
type: integer
vm_name:
required: true
type: string
workflow:
default: examples.mistral-jinja-workbook-complex.main
immutable: true
type: string
runner_type: mistral-v2
102 changes: 102 additions & 0 deletions contrib/examples/actions/workflows/mistral-jinja-workbook-complex.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
version: "2.0"
name: examples.mistral-jinja-workbook-complex
description: >
A sample workflow that demonstrates nested workflows,
forks, join, and use of jinja expressions.
workflows:

main:
type: direct
input:
- vm_name
- cpu_cores
- memory_mb
output:
vm_id: '{{ _.vm_id }}'
ip: '{{ _.ip }}'
tasks:
register_dns:
action: core.local
input:
cmd: "sleep 1; printf 'Registering {{ _.vm_name }}...'"
publish:
ip: "10.1.23.98"
status_message: "DNS for {{ _.vm_name }} is registered."
on-success:
- configure_vm
- notify
create_vm:
wait-before: 1
workflow: create_vm
input:
name: '{{ _.vm_name }}'
cpu_cores: '{{ _.cpu_cores }}'
memory_mb: '{{ _.memory_mb }}'
publish:
vm_id: "{{ task('create_vm').result.vm_id }}"
status_message: "VM {{ _.vm_name }} is created."
on-success:
- configure_vm
- notify
configure_vm:
join: all
workflow: configure_vm
input:
vm_id: '{{ _.vm_id }}'
ip: '{{ _.ip }}'
publish:
status_message: "VM {{ _.vm_name }} is reconfigured."
on-success:
- close_request
- notify
close_request:
action: std.noop
publish:
status_message: "VM request is fulfilled."
on-success:
- notify
notify:
action: core.local
input:
cmd: "printf '{{ _.status_message }}'"

create_vm:
type: direct
input:
- name
- cpu_cores
- memory_mb
output:
vm_id: '{{ _.vm_id }}'
tasks:
create:
action: core.local
input:
cmd: "printf 'vm6789'; sleep 5"
publish:
vm_id: "{{ task('create').result.stdout }}"

configure_vm:
type: direct
input:
- vm_id
- ip
vars:
apps:
- 'super mario brothers'
- 'zelda'
- 'donkey kong'
tasks:
add_disks:
action: core.local
input:
cmd: "sleep 1; printf 'disks created'"
add_nics:
action: core.local
input:
cmd: "sleep 1; printf 'nics created'"
install_apps:
action: core.local
input:
cmd: "sleep 1; {% for app in _.apps %}printf '{{ app }} is installed.\n'; {% endfor %}"
9 changes: 8 additions & 1 deletion st2tests/integration/mistral/test_wiring.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,20 @@ def test_basic_workbook(self):
self._assert_success(execution, num_tasks=1)
self.assertIn('stdout', execution.result)

def test_complex_workbook(self):
def test_complex_workbook_with_yaql(self):
execution = self._execute_workflow(
'examples.mistral-workbook-complex', {'vm_name': 'demo1'})
execution = self._wait_for_completion(execution)
self._assert_success(execution, num_tasks=8)
self.assertIn('vm_id', execution.result)

def test_complex_workbook_with_jinja(self):
execution = self._execute_workflow(
'examples.mistral-jinja-workbook-complex', {'vm_name': 'demo2'})
execution = self._wait_for_completion(execution)
self._assert_success(execution, num_tasks=8)
self.assertIn('vm_id', execution.result)

def test_complex_workbook_subflow_actions(self):
execution = self._execute_workflow(
'examples.mistral-workbook-subflows', {'subject': 'st2', 'adjective': 'cool'})
Expand Down

0 comments on commit 0b1d4e4

Please sign in to comment.