summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorflowerysong <paul.arthur@flowerysong.com>2024-07-05 19:27:45 +0200
committerGitHub <noreply@github.com>2024-07-05 19:27:45 +0200
commit63538f777950e972ec04967a94db8d7c5758daac (patch)
tree5f6a514957b6b2079648141f26e3db4a52112280 /test
parentlinear: fix included handlers executing in lockstep (#83209) (diff)
downloadansible-63538f777950e972ec04967a94db8d7c5758daac.tar.xz
ansible-63538f777950e972ec04967a94db8d7c5758daac.zip
package_facts: fix warning logic (#83520)
* package_facts: fix warning logic * Refactor so that warnings can work
Diffstat (limited to 'test')
-rw-r--r--test/integration/targets/package_facts/aliases1
-rw-r--r--test/integration/targets/package_facts/files/apk3
-rwxr-xr-xtest/integration/targets/package_facts/runme.sh15
-rw-r--r--test/integration/targets/package_facts/runme.yml4
-rw-r--r--test/integration/targets/package_facts/test_warning_failed.yml26
-rw-r--r--test/integration/targets/package_facts/test_warning_unusable.yml12
6 files changed, 61 insertions, 0 deletions
diff --git a/test/integration/targets/package_facts/aliases b/test/integration/targets/package_facts/aliases
index f5edf4b117..eedfe259b6 100644
--- a/test/integration/targets/package_facts/aliases
+++ b/test/integration/targets/package_facts/aliases
@@ -1,2 +1,3 @@
+destructive
shippable/posix/group2
skip/macos
diff --git a/test/integration/targets/package_facts/files/apk b/test/integration/targets/package_facts/files/apk
new file mode 100644
index 0000000000..2bb8d868bd
--- /dev/null
+++ b/test/integration/targets/package_facts/files/apk
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exit 1
diff --git a/test/integration/targets/package_facts/runme.sh b/test/integration/targets/package_facts/runme.sh
new file mode 100755
index 0000000000..e1b21599ce
--- /dev/null
+++ b/test/integration/targets/package_facts/runme.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+set -eux
+
+ansible-playbook -i ../../inventory runme.yml -v "$@"
+
+ansible-playbook -i ../../inventory test_warning_unusable.yml -v "$@" 2>&1 | tee output.log
+if ! grep -q "Conditional result was False" output.log; then
+ grep "Requested package manager apk was not usable by this module" output.log
+fi
+
+ansible-playbook -i ../../inventory test_warning_failed.yml -v "$@" 2>&1 | tee output.log
+if ! grep -q "Conditional result was False" output.log; then
+ grep "Failed to retrieve packages with apk: Unable to list packages" output.log
+fi
diff --git a/test/integration/targets/package_facts/runme.yml b/test/integration/targets/package_facts/runme.yml
new file mode 100644
index 0000000000..4724d7639c
--- /dev/null
+++ b/test/integration/targets/package_facts/runme.yml
@@ -0,0 +1,4 @@
+- hosts: all
+ gather_facts: true
+ roles:
+ - { role: ../package_facts }
diff --git a/test/integration/targets/package_facts/test_warning_failed.yml b/test/integration/targets/package_facts/test_warning_failed.yml
new file mode 100644
index 0000000000..1246bda206
--- /dev/null
+++ b/test/integration/targets/package_facts/test_warning_failed.yml
@@ -0,0 +1,26 @@
+- hosts: all
+ tasks:
+ - name: Check for apk
+ ansible.builtin.command: apk info
+ ignore_errors: true
+ register: apk_exists
+
+ - when: apk_exists is failed
+ block:
+ - name: Create a mock apk
+ ansible.builtin.copy:
+ dest: /usr/bin/apk
+ src: apk
+ mode: "0755"
+ become: true
+
+ - name: Elicit a warning about failing to list packages
+ ansible.builtin.package_facts:
+ manager: apk
+ failed_when: false
+
+ - name: Remove the mock
+ ansible.builtin.file:
+ dest: /usr/bin/apk
+ state: absent
+ become: true
diff --git a/test/integration/targets/package_facts/test_warning_unusable.yml b/test/integration/targets/package_facts/test_warning_unusable.yml
new file mode 100644
index 0000000000..3379f98bd0
--- /dev/null
+++ b/test/integration/targets/package_facts/test_warning_unusable.yml
@@ -0,0 +1,12 @@
+- hosts: all
+ tasks:
+ - name: Check for apk
+ ansible.builtin.command: apk info
+ ignore_errors: true
+ register: apk_exists
+
+ - name: Elicit a warning about the missing binary
+ ansible.builtin.package_facts:
+ manager: apk
+ when: apk_exists is failed
+ failed_when: false