From f4bd3be71fb17360a91d7e1497776999d0baff78 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 3 Feb 2016 14:53:47 -0500 Subject: [PATCH] Adding block integration tests --- test/integration/Makefile | 9 +- test/integration/block_test.out | 63 +++++++++++ test/integration/test_blocks/block_test.out | 57 ++++++++++ test/integration/test_blocks/fail.yml | 1 + test/integration/test_blocks/main.yml | 101 ++++++++++++++++++ test/integration/test_blocks/nested_fail.yml | 3 + .../test_blocks/nested_nested_fail.yml | 3 + 7 files changed, 236 insertions(+), 1 deletion(-) create mode 100644 test/integration/block_test.out create mode 100644 test/integration/test_blocks/block_test.out create mode 100644 test/integration/test_blocks/fail.yml create mode 100644 test/integration/test_blocks/main.yml create mode 100644 test/integration/test_blocks/nested_fail.yml create mode 100644 test/integration/test_blocks/nested_nested_fail.yml diff --git a/test/integration/Makefile b/test/integration/Makefile index 8f2e880305..28f7224eb9 100644 --- a/test/integration/Makefile +++ b/test/integration/Makefile @@ -21,7 +21,7 @@ VAULT_PASSWORD_FILE = vault-password CONSUL_RUNNING := $(shell python consul_running.py) -all: parsing test_var_precedence unicode test_templating_settings environment non_destructive destructive includes pull check_mode test_hash test_handlers test_group_by test_vault test_tags test_lookup_paths no_log +all: parsing test_var_precedence unicode test_templating_settings environment non_destructive destructive includes blocks pull check_mode test_hash test_handlers test_group_by test_vault test_tags test_lookup_paths no_log parsing: ansible-playbook bad_parsing.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -vvv $(TEST_FLAGS) --tags prepare,common,scenario5 @@ -127,6 +127,13 @@ test_tags: # Skip one tag [ "$$(ansible-playbook --list-tasks --skip-tags tag test_tags.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS) | fgrep Task_with | xargs)" = "Task_with_always_tag TAGS: [always] Task_without_tag TAGS: []" ] +blocks: + # remove old output log + rm -f block_test.out + # run test + ansible-playbook -vv test_blocks/main.yml | tee block_test.out + # ensure each test ran + [ "$$(grep 'TEST COMPLETE' block_test.out | wc -l)" == "$$(egrep '^[0-9]+ plays in' block_test.out | cut -f1 -d' ')" ] cloud: amazon rackspace azure diff --git a/test/integration/block_test.out b/test/integration/block_test.out new file mode 100644 index 0000000000..7ba056ae58 --- /dev/null +++ b/test/integration/block_test.out @@ -0,0 +1,63 @@ +Using /etc/ansible/ansible.cfg as config file +2 plays in test_blocks/main.yml + +PLAY [simple block test] ******************************************************* + +TASK [setup] ******************************************************************* +ok: [localhost] + +TASK [set block tasks run flag] ************************************************ +ok: [localhost] => {"ansible_facts": {"block_tasks_run": true}, "changed": false} + +TASK [fail in tasks] *********************************************************** +fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failed as requested from task"} + +TASK [set block rescue run flag] *********************************************** +ok: [localhost] => {"ansible_facts": {"block_rescue_run": true}, "changed": false} + +TASK [fail in rescue] ********************************************************** +fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failed as requested from task"} + +TASK [set block always run flag] *********************************************** +ok: [localhost] => {"ansible_facts": {"block_always_run": true}, "changed": false} + +TASK [set nested block always run flag] **************************************** +ok: [localhost] => {"ansible_facts": {"nested_block_always_run": true}, "changed": false} + +TASK [fail in always] ********************************************************** +fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failed as requested from task"} + +TASK [assert] ****************************************************************** +ok: [localhost] => {"changed": false, "msg": "all assertions passed"} + +TASK [debug] ******************************************************************* +ok: [localhost] => { + "msg": "TEST COMPLETE" +} + +PLAY [block with includes] ***************************************************** + +TASK [setup] ******************************************************************* +ok: [localhost] + +TASK [include fail.yml in tasks] *********************************************** +included: /data/devel/ansible/test/integration/test_blocks/fail.yml for localhost + +TASK [fail] ******************************************************************** +fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "failed from tasks"} + +TASK [set_fact] **************************************************************** +ok: [localhost] => {"ansible_facts": {"rescue_run_after_include_fail": true}, "changed": false} + +TASK [include fail.yml in rescue] ********************************************** +included: /data/devel/ansible/test/integration/test_blocks/fail.yml for localhost + +TASK [fail] ******************************************************************** +fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "failed from rescue"} + +TASK [set_fact] **************************************************************** +ok: [localhost] => {"ansible_facts": {"always_run_after_include_fail_in_rescue": true}, "changed": false} + +PLAY RECAP ********************************************************************* +localhost : ok=12 changed=0 unreachable=0 failed=3 + diff --git a/test/integration/test_blocks/block_test.out b/test/integration/test_blocks/block_test.out new file mode 100644 index 0000000000..7c17d0094b --- /dev/null +++ b/test/integration/test_blocks/block_test.out @@ -0,0 +1,57 @@ +Using /etc/ansible/ansible.cfg as config file +2 plays in test.yml + +PLAY [simple block test] ******************************************************* + +TASK [setup] ******************************************************************* +ok: [localhost] + +TASK [set block tasks run flag] ************************************************ +ok: [localhost] => {"ansible_facts": {"block_tasks_run": true}, "changed": false} + +TASK [fail in tasks] *********************************************************** +fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failed as requested from task"} + +TASK [set block rescue run flag] *********************************************** +ok: [localhost] => {"ansible_facts": {"block_rescue_run": true}, "changed": false} + +TASK [fail in rescue] ********************************************************** +fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failed as requested from task"} + +TASK [set block always run flag] *********************************************** +ok: [localhost] => {"ansible_facts": {"block_always_run": true}, "changed": false} + +TASK [set nested block always run flag] **************************************** +ok: [localhost] => {"ansible_facts": {"nested_block_always_run": true}, "changed": false} + +TASK [fail in always] ********************************************************** +fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failed as requested from task"} + +TASK [assert] ****************************************************************** +ok: [localhost] => {"changed": false, "msg": "all assertions passed"} + +TASK [debug] ******************************************************************* +ok: [localhost] => { + "msg": "TEST COMPLETE" +} + +PLAY [block with includes] ***************************************************** + +TASK [setup] ******************************************************************* +ok: [localhost] + +TASK [include fail.yml in tasks] *********************************************** +included: /root/testing/test_blocks/fail.yml for localhost + +TASK [fail] ******************************************************************** +fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "failed from tasks"} + +TASK [set_fact] **************************************************************** +ok: [localhost] => {"ansible_facts": {"rescue_run_after_include_fail": true}, "changed": false} + +TASK [set_fact] **************************************************************** +ok: [localhost] => {"ansible_facts": {"always_run_after_include_fail_in_rescue": true}, "changed": false} + +PLAY RECAP ********************************************************************* +localhost : ok=11 changed=0 unreachable=0 failed=2 + diff --git a/test/integration/test_blocks/fail.yml b/test/integration/test_blocks/fail.yml new file mode 100644 index 0000000000..ca8575a907 --- /dev/null +++ b/test/integration/test_blocks/fail.yml @@ -0,0 +1 @@ +- fail: msg="{{msg}}" diff --git a/test/integration/test_blocks/main.yml b/test/integration/test_blocks/main.yml new file mode 100644 index 0000000000..1e0641ba00 --- /dev/null +++ b/test/integration/test_blocks/main.yml @@ -0,0 +1,101 @@ +- name: simple block test + hosts: localhost + gather_facts: yes + 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: 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: 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 + 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: tasks 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/test_blocks/nested_fail.yml b/test/integration/test_blocks/nested_fail.yml new file mode 100644 index 0000000000..31ae870e37 --- /dev/null +++ b/test/integration/test_blocks/nested_fail.yml @@ -0,0 +1,3 @@ +- include: fail.yml + args: + msg: "nested {{msg}}" diff --git a/test/integration/test_blocks/nested_nested_fail.yml b/test/integration/test_blocks/nested_nested_fail.yml new file mode 100644 index 0000000000..e9a050fb98 --- /dev/null +++ b/test/integration/test_blocks/nested_nested_fail.yml @@ -0,0 +1,3 @@ +- include: nested_fail.yml + args: + msg: "nested {{msg}}"