From 391a951f70381246bddfa677e08aaad221e086e3 Mon Sep 17 00:00:00 2001 From: Major Hayden Date: Wed, 7 Mar 2018 16:02:33 -0600 Subject: [PATCH] Improve idempotency These discovery tasks always show up as "changed" in the Ansible output. This patch ensures that they are not labeled as changed when they are run. The patch also fixes the idempotency check grep so that it works properly with multiple hosts. Previously, if *any* of the hosts finished with no changes/failures, the entire job was marked as passing the idempotency tests. Depends-On: I17748b0dd2307fd9bee705140c67883140090298 Change-Id: Ie414d32d39fdeeedd77fe94b57a09ba344084ec1 Signed-off-by: Major Hayden --- common-tasks/test-force-package-cache-update.yml | 1 + common-tasks/test-set-nodepool-vars.yml | 5 +++++ test-ansible-functional.sh | 9 +++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/common-tasks/test-force-package-cache-update.yml b/common-tasks/test-force-package-cache-update.yml index e9bf9473..4b16b4e4 100644 --- a/common-tasks/test-force-package-cache-update.yml +++ b/common-tasks/test-force-package-cache-update.yml @@ -20,5 +20,6 @@ retries: 5 delay: 2 until: _update | succeeded + changed_when: false when: - ansible_pkg_mgr == 'apt' diff --git a/common-tasks/test-set-nodepool-vars.yml b/common-tasks/test-set-nodepool-vars.yml index 2068d96e..266aced7 100644 --- a/common-tasks/test-set-nodepool-vars.yml +++ b/common-tasks/test-set-nodepool-vars.yml @@ -27,6 +27,7 @@ executable: /bin/bash register: lxc_reverse_proxy delegate_to: localhost + changed_when: false when: - nodepool.stat.exists | bool tags: @@ -46,6 +47,7 @@ executable: /bin/bash register: uca_repo_url delegate_to: localhost + changed_when: false when: - ansible_pkg_mgr == 'apt' - nodepool.stat.exists | bool @@ -67,6 +69,7 @@ executable: /bin/bash register: centos_mirror_url delegate_to: localhost + changed_when: false when: - ansible_pkg_mgr in ['yum', 'dnf'] - nodepool.stat.exists | bool @@ -89,6 +92,7 @@ executable: /bin/bash register: _opensuse_mirror delegate_to: localhost + changed_when: false when: - ansible_pkg_mgr == 'zypper' - nodepool.stat.exists | bool @@ -126,6 +130,7 @@ executable: /bin/bash register: _pypi_wheel_mirror delegate_to: localhost + changed_when: false when: - nodepool.stat.exists | bool diff --git a/test-ansible-functional.sh b/test-ansible-functional.sh index 74103764..f12c37c6 100755 --- a/test-ansible-functional.sh +++ b/test-ansible-functional.sh @@ -135,12 +135,13 @@ if [ "${TEST_IDEMPOTENCE}" == "true" ]; then # Execute the test playbook execute_ansible_playbook - # Check the output log for changed/failed tasks - if grep -q "changed=0.*failed=0" ${ANSIBLE_LOG_PATH}; then - echo "Idempotence test: pass" - else + # Exit with a failure if we find "changed" or "failed" followed by anything + # other than a zero. + if grep -qP '(changed|failed)=(?!0)' ${ANSIBLE_LOG_PATH}; then echo "Idempotence test: fail" exit 1 + else + echo "Idempotence test: pass" fi fi