mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
tests: add handler listen test cases
This commit is contained in:
parent
fed079e4cb
commit
6c2af29659
5 changed files with 163 additions and 0 deletions
|
@ -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
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
- name: notify some handlers from a role
|
||||||
|
command: uptime
|
||||||
|
notify:
|
||||||
|
- notify_listen_from_role
|
||||||
|
- notify_listen_in_role
|
|
@ -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 \
|
[ "$(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]" ]
|
| 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 "$@"
|
||||||
|
|
||||||
|
|
|
@ -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
|
123
test/integration/targets/handlers/test_handlers_listen.yml
Normal file
123
test/integration/targets/handlers/test_handlers_listen.yml
Normal file
|
@ -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
|
Loading…
Reference in a new issue