mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Split integration tests out from Makefile. (#17976)
This commit is contained in:
parent
bf3d546d9a
commit
80a5c70ad7
169 changed files with 612 additions and 420 deletions
6
test/integration/targets/handlers/inventory.handlers
Normal file
6
test/integration/targets/handlers/inventory.handlers
Normal file
|
@ -0,0 +1,6 @@
|
|||
[testgroup]
|
||||
A
|
||||
B
|
||||
C
|
||||
D
|
||||
E
|
|
@ -0,0 +1,2 @@
|
|||
- name: echoing handler
|
||||
command: echo CALLED_HANDLER_{{ inventory_hostname }}
|
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
|
||||
# We notify for A and B, and hosts B and C fail.
|
||||
# When forcing, we expect A and B to run handlers
|
||||
# When not forcing, we expect only B to run handlers
|
||||
|
||||
- name: notify the handler for host A and B
|
||||
shell: echo
|
||||
notify:
|
||||
- echoing handler
|
||||
when: inventory_hostname == 'A' or inventory_hostname == 'B'
|
||||
|
||||
- name: EXPECTED FAILURE fail task for all
|
||||
fail: msg="Fail All"
|
||||
when: fail_all is defined and fail_all
|
||||
|
||||
- name: EXPECTED FAILURE fail task for A
|
||||
fail: msg="Fail A"
|
||||
when: inventory_hostname == 'A'
|
||||
|
||||
- name: EXPECTED FAILURE fail task for C
|
||||
fail: msg="Fail C"
|
||||
when: inventory_hostname == 'C'
|
||||
|
||||
- name: echo after A and C have failed
|
||||
command: echo CALLED_TASK_{{ inventory_hostname }}
|
|
@ -0,0 +1,5 @@
|
|||
- name: set handler fact
|
||||
set_fact:
|
||||
handler_called: True
|
||||
- name: test handler
|
||||
debug: msg="handler called"
|
|
@ -0,0 +1,2 @@
|
|||
dependencies: []
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
# test code for the async keyword
|
||||
# (c) 2014, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
- name: reset handler_called variable to false for all hosts
|
||||
set_fact:
|
||||
handler_called: False
|
||||
tags: scenario1
|
||||
|
||||
- name: notify the handler for host A only
|
||||
shell: echo
|
||||
notify:
|
||||
- set handler fact
|
||||
when: inventory_hostname == 'A'
|
||||
tags: scenario1
|
||||
|
||||
- name: force handler execution now
|
||||
meta: "flush_handlers"
|
||||
tags: scenario1
|
||||
|
||||
- debug: var=handler_called
|
||||
tags: scenario1
|
||||
|
||||
- name: validate the handler only ran on one host
|
||||
assert:
|
||||
that:
|
||||
- "inventory_hostname == 'A' and handler_called == True or handler_called == False"
|
||||
tags: scenario1
|
||||
|
||||
- name: 'test notify with loop'
|
||||
debug: msg='a task'
|
||||
changed_when: item == 1
|
||||
notify: test handler
|
||||
with_items:
|
||||
- 1
|
||||
- 2
|
||||
tags: scenario2
|
|
@ -0,0 +1,7 @@
|
|||
- name: set_handler_fact_1
|
||||
set_fact:
|
||||
handler1_called: True
|
||||
|
||||
- name: set_handler_fact_2
|
||||
set_fact:
|
||||
handler2_called: True
|
|
@ -0,0 +1,41 @@
|
|||
# test code for the async keyword
|
||||
# (c) 2014, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
- name: notify the first handler
|
||||
shell: echo
|
||||
notify:
|
||||
- set_handler_fact_1
|
||||
|
||||
- name: force handler execution now
|
||||
meta: "flush_handlers"
|
||||
|
||||
- name: assert handler1 ran and not handler2
|
||||
assert:
|
||||
that:
|
||||
- "handler1_called is defined"
|
||||
- "handler2_called is not defined"
|
||||
|
||||
- name: reset handler1_called
|
||||
set_fact:
|
||||
handler1_called: False
|
||||
|
||||
- name: notify the second handler
|
||||
shell: echo
|
||||
notify:
|
||||
- set_handler_fact_2
|
||||
|
36
test/integration/targets/handlers/runme.sh
Executable file
36
test/integration/targets/handlers/runme.sh
Executable file
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -eux
|
||||
|
||||
ansible-playbook test_handlers.yml -i inventory.handlers -v "$@" --tags scenario1
|
||||
|
||||
[ "$(ansible-playbook test_handlers.yml -i inventory.handlers -v "$@" --tags scenario2 -l A \
|
||||
| egrep -o 'RUNNING HANDLER \[test_handlers : .*?]')" = "RUNNING HANDLER [test_handlers : test handler]" ]
|
||||
|
||||
# Not forcing, should only run on successful host
|
||||
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal \
|
||||
| egrep -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ]
|
||||
|
||||
# Forcing from command line
|
||||
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal --force-handlers \
|
||||
| egrep -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
|
||||
|
||||
# Forcing from command line, should only run later tasks on unfailed hosts
|
||||
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal --force-handlers \
|
||||
| egrep -o CALLED_TASK_. | sort | uniq | xargs)" = "CALLED_TASK_B CALLED_TASK_D CALLED_TASK_E" ]
|
||||
|
||||
# Forcing from command line, should call handlers even if all hosts fail
|
||||
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal --force-handlers -e fail_all=yes \
|
||||
| egrep -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
|
||||
|
||||
# Forcing from ansible.cfg
|
||||
[ "$(ANSIBLE_FORCE_HANDLERS=true ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal \
|
||||
| egrep -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
|
||||
|
||||
# Forcing true in play
|
||||
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags force_true_in_play \
|
||||
| egrep -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
|
||||
|
||||
# Forcing false in play, which overrides command line
|
||||
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags force_false_in_play --force-handlers \
|
||||
| egrep -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ]
|
30
test/integration/targets/handlers/test_force_handlers.yml
Normal file
30
test/integration/targets/handlers/test_force_handlers.yml
Normal file
|
@ -0,0 +1,30 @@
|
|||
---
|
||||
|
||||
- name: test force handlers (default)
|
||||
tags: normal
|
||||
hosts: testgroup
|
||||
gather_facts: False
|
||||
connection: local
|
||||
roles:
|
||||
- { role: test_force_handlers }
|
||||
tasks:
|
||||
- debug: msg="you should see this with --tags=normal"
|
||||
|
||||
- name: test force handlers (set to true)
|
||||
tags: force_true_in_play
|
||||
hosts: testgroup
|
||||
gather_facts: False
|
||||
connection: local
|
||||
force_handlers: True
|
||||
roles:
|
||||
- { role: test_force_handlers, tags: force_true_in_play }
|
||||
|
||||
|
||||
- name: test force handlers (set to false)
|
||||
tags: force_false_in_play
|
||||
hosts: testgroup
|
||||
gather_facts: False
|
||||
connection: local
|
||||
force_handlers: False
|
||||
roles:
|
||||
- { role: test_force_handlers, tags: force_false_in_play }
|
26
test/integration/targets/handlers/test_handlers.yml
Normal file
26
test/integration/targets/handlers/test_handlers.yml
Normal file
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
- name: run handlers
|
||||
hosts: A
|
||||
gather_facts: False
|
||||
connection: local
|
||||
roles:
|
||||
- { role: test_handlers_meta, tags: ['scenario1'] }
|
||||
|
||||
- name: verify final handler was run
|
||||
hosts: A
|
||||
gather_facts: False
|
||||
connection: local
|
||||
tasks:
|
||||
- name: verify handler2 ran
|
||||
assert:
|
||||
that:
|
||||
- "not hostvars[inventory_hostname]['handler1_called']"
|
||||
- "'handler2_called' in hostvars[inventory_hostname]"
|
||||
tags: ['scenario1']
|
||||
|
||||
- name: test handlers
|
||||
hosts: testgroup
|
||||
gather_facts: False
|
||||
connection: local
|
||||
roles:
|
||||
- { role: test_handlers }
|
Loading…
Add table
Add a link
Reference in a new issue