diff options
author | Matt Clay <matt@mystile.com> | 2016-10-12 23:57:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-12 23:57:53 +0200 |
commit | 80a5c70ad795f3cd1e6e3edde7077a8dfd65470b (patch) | |
tree | 50ab0ad670d2631fa32cad47019d9a970ed81596 /test/integration/targets/blocks | |
parent | Only dispkay failure to use cryptography at a higher verbosity (diff) | |
download | ansible-80a5c70ad795f3cd1e6e3edde7077a8dfd65470b.tar.xz ansible-80a5c70ad795f3cd1e6e3edde7077a8dfd65470b.zip |
Split integration tests out from Makefile. (#17976)
Diffstat (limited to 'test/integration/targets/blocks')
-rw-r--r-- | test/integration/targets/blocks/fail.yml | 2 | ||||
-rw-r--r-- | test/integration/targets/blocks/main.yml | 103 | ||||
-rw-r--r-- | test/integration/targets/blocks/nested_fail.yml | 3 | ||||
-rw-r--r-- | test/integration/targets/blocks/nested_nested_fail.yml | 3 | ||||
-rwxr-xr-x | test/integration/targets/blocks/runme.sh | 20 |
5 files changed, 131 insertions, 0 deletions
diff --git a/test/integration/targets/blocks/fail.yml b/test/integration/targets/blocks/fail.yml new file mode 100644 index 0000000000..ae94655136 --- /dev/null +++ b/test/integration/targets/blocks/fail.yml @@ -0,0 +1,2 @@ +- name: EXPECTED FAILURE + fail: msg="{{msg}}" diff --git a/test/integration/targets/blocks/main.yml b/test/integration/targets/blocks/main.yml new file mode 100644 index 0000000000..a80a62b753 --- /dev/null +++ b/test/integration/targets/blocks/main.yml @@ -0,0 +1,103 @@ +- name: simple block test + hosts: localhost + gather_facts: yes + strategy: "{{test_strategy|default('linear')}}" + vars: + block_tasks_run: false + block_rescue_run: false + block_always_run: false + nested_block_always_run: false + tasks_run_after_failure: false + rescue_run_after_failure: false + always_run_after_failure: false + tasks: + - block: + - name: set block tasks run flag + set_fact: + block_tasks_run: true + - name: EXPECTED FAILURE fail in tasks + fail: + - name: tasks flag should not be set after failure + set_fact: + tasks_run_after_failure: true + rescue: + - name: set block rescue run flag + set_fact: + block_rescue_run: true + - name: EXPECTED FAILURE fail in rescue + fail: + - name: tasks flag should not be set after failure in rescue + set_fact: + rescue_run_after_failure: true + always: + - name: set block always run flag + set_fact: + block_always_run: true + #- block: + # - meta: noop + # always: + # - name: set nested block always run flag + # set_fact: + # nested_block_always_run: true + # - name: fail in always + # fail: + # - name: tasks flag should not be set after failure in always + # set_fact: + # always_run_after_failure: true + - meta: clear_host_errors + + post_tasks: + - assert: + that: + - block_tasks_run + - block_rescue_run + - block_always_run + #- nested_block_always_run + - not tasks_run_after_failure + - not rescue_run_after_failure + - not always_run_after_failure + - debug: msg="TEST COMPLETE" + +- name: block with includes + hosts: localhost + gather_facts: yes + strategy: "{{test_strategy|default('linear')}}" + vars: + rescue_run_after_include_fail: false + always_run_after_include_fail_in_rescue: false + tasks_run_after_failure: false + rescue_run_after_failure: false + always_run_after_failure: false + tasks: + - block: + - name: include fail.yml in tasks + include: fail.yml + args: + msg: "failed from tasks" + - name: tasks flag should not be set after failure + set_fact: + tasks_run_after_failure: true + rescue: + - set_fact: + rescue_run_after_include_fail: true + - name: include fail.yml in rescue + include: fail.yml + args: + msg: "failed from rescue" + - name: flag should not be set after failure in rescue + set_fact: + rescue_run_after_failure: true + always: + - set_fact: + always_run_after_include_fail_in_rescue: true + - meta: clear_host_errors + + post_tasks: + - assert: + that: + - rescue_run_after_include_fail + - always_run_after_include_fail_in_rescue + - not tasks_run_after_failure + - not rescue_run_after_failure + - not always_run_after_failure + - debug: msg="TEST COMPLETE" diff --git a/test/integration/targets/blocks/nested_fail.yml b/test/integration/targets/blocks/nested_fail.yml new file mode 100644 index 0000000000..31ae870e37 --- /dev/null +++ b/test/integration/targets/blocks/nested_fail.yml @@ -0,0 +1,3 @@ +- include: fail.yml + args: + msg: "nested {{msg}}" diff --git a/test/integration/targets/blocks/nested_nested_fail.yml b/test/integration/targets/blocks/nested_nested_fail.yml new file mode 100644 index 0000000000..e9a050fb98 --- /dev/null +++ b/test/integration/targets/blocks/nested_nested_fail.yml @@ -0,0 +1,3 @@ +- include: nested_fail.yml + args: + msg: "nested {{msg}}" diff --git a/test/integration/targets/blocks/runme.sh b/test/integration/targets/blocks/runme.sh new file mode 100755 index 0000000000..dd15a10083 --- /dev/null +++ b/test/integration/targets/blocks/runme.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -eux + +# remove old output log +rm -f block_test.out +# run the test and check to make sure the right number of completions was logged +ansible-playbook -vv main.yml -i ../../inventory "$@" | tee block_test.out +env python -c \ + 'import sys, re; sys.stdout.write(re.sub("\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]", "", sys.stdin.read()))' \ + <block_test.out >block_test_wo_colors.out +[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(egrep '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ] +# cleanup the output log again, to make sure the test is clean +rm -f block_test.out block_test_wo_colors.out +# run test with free strategy and again count the completions +ansible-playbook -vv main.yml -i ../../inventory -e test_strategy=free "$@" | tee block_test.out +env python -c \ + 'import sys, re; sys.stdout.write(re.sub("\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]", "", sys.stdin.read()))' \ + <block_test.out >block_test_wo_colors.out +[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(egrep '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ] |