diff --git a/test/integration/targets/handlers/roles/test_handlers_listen/handlers/main.yml b/test/integration/targets/handlers/roles/test_handlers_listen/handlers/main.yml new file mode 100644 index 00000000000..3bfd82a2546 --- /dev/null +++ b/test/integration/targets/handlers/roles/test_handlers_listen/handlers/main.yml @@ -0,0 +1,10 @@ +--- +- name: notify_listen_ran_4_3 + set_fact: + notify_listen_ran_4_3: True + listen: notify_listen + +- name: notify_listen_in_role_4 + set_fact: + notify_listen_in_role_4: True + listen: notify_listen_in_role diff --git a/test/integration/targets/handlers/roles/test_handlers_listen/tasks/main.yml b/test/integration/targets/handlers/roles/test_handlers_listen/tasks/main.yml new file mode 100644 index 00000000000..bac9b71e317 --- /dev/null +++ b/test/integration/targets/handlers/roles/test_handlers_listen/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: notify some handlers from a role + command: uptime + notify: + - notify_listen_from_role + - notify_listen_in_role diff --git a/test/integration/targets/handlers/runme.sh b/test/integration/targets/handlers/runme.sh index 9b709de3269..bafdbcce308 100755 --- a/test/integration/targets/handlers/runme.sh +++ b/test/integration/targets/handlers/runme.sh @@ -41,3 +41,16 @@ ansible-playbook test_listening_handlers.yml -i inventory.handlers -v "$@" [ "$(ansible-playbook test_handlers_include.yml -i ../../inventory -v "$@" --tags role_include_handlers \ | egrep -o 'RUNNING HANDLER \[test_handlers_include : .*?]')" = "RUNNING HANDLER [test_handlers_include : test handler]" ] + +# Notify handler listen +ansible-playbook test_handlers_listen.yml -i inventory.handlers -v "$@" + +# Notify inexistent handlers results in error +set +e +result="$(ansible-playbook test_handlers_inexistent_notify.yml -i inventory.handlers "$@" 2>&1)" +set -e +grep -q "ERROR! The requested handler 'notify_inexistent_handler' was not found in either the main handlers list nor in the listening handlers list" <<< "$result" + +# Notify inexistent handlers without errors when ANSIBLE_ERROR_ON_MISSING_HANDLER=false +ANSIBLE_ERROR_ON_MISSING_HANDLER=false ansible-playbook test_handlers_inexistent_notify.yml -i inventory.handlers -v "$@" + diff --git a/test/integration/targets/handlers/test_handlers_inexistent_notify.yml b/test/integration/targets/handlers/test_handlers_inexistent_notify.yml new file mode 100644 index 00000000000..f1c99efe124 --- /dev/null +++ b/test/integration/targets/handlers/test_handlers_inexistent_notify.yml @@ -0,0 +1,11 @@ +--- +- name: notify inexistent handler + hosts: localhost + gather_facts: false + connection: local + tasks: + - name: test notify an inexistent handler + command: uptime + notify: + - notify_inexistent_handler + register: result diff --git a/test/integration/targets/handlers/test_handlers_listen.yml b/test/integration/targets/handlers/test_handlers_listen.yml new file mode 100644 index 00000000000..b892af3b15d --- /dev/null +++ b/test/integration/targets/handlers/test_handlers_listen.yml @@ -0,0 +1,123 @@ +--- +- name: test listen with named handlers + hosts: localhost + gather_facts: false + connection: local + tasks: + - name: test notify handlers listen + command: uptime + notify: + - notify_listen + - meta: flush_handlers + - name: verify test notify handlers listen + assert: + that: + - "notify_listen_ran_1_1 is defined" + - "notify_listen_ran_1_2 is defined" + handlers: + - name: notify_handler_ran_1_1 + set_fact: + notify_listen_ran_1_1: True + listen: notify_listen + - name: notify_handler_ran_1_2 + set_fact: + notify_listen_ran_1_2: True + listen: notify_listen + +- name: test listen unnamed handlers + hosts: localhost + gather_facts: false + connection: local + pre_tasks: + - name: notify some handlers + command: echo foo + notify: + - notify_listen + tasks: + - meta: flush_handlers + - name: assert all defined handlers ran without error + assert: + that: + - "notify_listen_ran_1 is defined" + - "notify_listen_ran_2 is defined" + handlers: + - set_fact: + notify_listen_ran_1: True + listen: notify_listen + - set_fact: + notify_listen_ran_2: True + listen: notify_listen + +- name: test with mixed notify by name and listen + hosts: localhost + gather_facts: false + connection: local + tasks: + - name: test notify handlers names and identical listen + command: uptime + notify: + - notify_listen + - meta: flush_handlers + - name: verify test notify handlers names and identical listen + assert: + that: + - "notify_handler_name_ran_3 is defined" + - "notify_handler_name_ran_3_1 is not defined" + - "notify_listen_ran_3_2 is defined" + - "notify_listen_ran_3_3 is defined" + - "not_notify_listen_3_4 is not defined" + handlers: + - name: notify_listen + set_fact: + notify_handler_name_ran_3: True + # this will not run as we have a handler with a identical name notified first + - name: notify_listen + set_fact: + notify_handler_name_ran_3_1: True + - name: notify_handler_ran_3_2 + set_fact: + notify_listen_ran_3_2: True + listen: notify_listen + - name: notify_handler_ran_3_3 + set_fact: + notify_listen_ran_3_3: True + listen: notify_listen + # this one is not notified + - name: not_notify_listen_3_4 + set_fact: + not_notify_listen_3_4: True + listen: not_notified + +- name: test listen in roles + hosts: localhost + gather_facts: false + connection: local + roles: + - role: test_handlers_listen + tasks: + - name: test notify handlers listen in roles + command: uptime + notify: + - notify_listen + - meta: flush_handlers + - name: verify test notify handlers listen in roles + assert: + that: + - "notify_listen_ran_4_1 is defined" + - "notify_listen_ran_4_2 is defined" + - "notify_listen_ran_4_3 is defined" + - "notify_listen_in_role_4 is defined" + - "notify_listen_from_role_4 is defined" + handlers: + - name: notify_listen_ran_4_1 + set_fact: + notify_listen_ran_4_1: True + listen: notify_listen + - name: notify_listen_ran_4_2 + set_fact: + notify_listen_ran_4_2: True + listen: notify_listen + - name: notify_listen_from_role_4 + set_fact: + notify_listen_from_role_4: True + listen: notify_listen_from_role