From aa23ea8462430a2b3b17a3a869a63c1617389ee2 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Mon, 20 Jul 2015 14:11:31 +0200 Subject: [PATCH] tests: checks that handlers work with loops --- test/integration/Makefile | 3 ++- .../roles/test_handlers/handlers/main.yml | 2 ++ .../integration/roles/test_handlers/tasks/main.yml | 14 ++++++++++++++ test/integration/test_handlers.yml | 3 ++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/test/integration/Makefile b/test/integration/Makefile index 3d4555b54f..ec790ae709 100644 --- a/test/integration/Makefile +++ b/test/integration/Makefile @@ -51,7 +51,8 @@ test_group_by: ansible-playbook test_group_by.yml -i inventory.group_by -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS) test_handlers: - ansible-playbook test_handlers.yml -i inventory.handlers -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS) + ansible-playbook test_handlers.yml --tags scenario1 -i inventory.handlers -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS) + [ "$$(ansible-playbook test_handlers.yml --tags scenario2 -l A -i inventory.handlers -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS) | grep -Po 'RUNNING HANDLER \[test_handlers : \K[^\]]+')" = "test handler" ] # Not forcing, should only run on successful host [ "$$(ansible-playbook test_force_handlers.yml --tags normal -i inventory.handlers -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS) | egrep -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ] # Forcing from command line diff --git a/test/integration/roles/test_handlers/handlers/main.yml b/test/integration/roles/test_handlers/handlers/main.yml index 117741f825..b8ee48b5c8 100644 --- a/test/integration/roles/test_handlers/handlers/main.yml +++ b/test/integration/roles/test_handlers/handlers/main.yml @@ -1,3 +1,5 @@ - name: set handler fact set_fact: handler_called: True +- name: test handler + debug: msg="handler called" diff --git a/test/integration/roles/test_handlers/tasks/main.yml b/test/integration/roles/test_handlers/tasks/main.yml index 6f11768188..1c1d819269 100644 --- a/test/integration/roles/test_handlers/tasks/main.yml +++ b/test/integration/roles/test_handlers/tasks/main.yml @@ -20,19 +20,33 @@ - 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 diff --git a/test/integration/test_handlers.yml b/test/integration/test_handlers.yml index 6a5366408c..dafa9ceebe 100644 --- a/test/integration/test_handlers.yml +++ b/test/integration/test_handlers.yml @@ -4,7 +4,7 @@ gather_facts: False connection: local roles: - - { role: test_handlers_meta } + - { role: test_handlers_meta, tags: ['scenario1'] } - name: verify final handler was run hosts: A @@ -16,6 +16,7 @@ that: - "not hostvars[inventory_hostname]['handler1_called']" - "'handler2_called' in hostvars[inventory_hostname]" + tags: ['scenario1'] - name: test handlers hosts: testgroup