backport GALAXY_COLLECTIONS_PATH_WARNINGS patch
This will be used in the Fedora ansible-packaging macros to silence useless warnings when installing collections into %{buildroot}.
This commit is contained in:
parent
491e0b3137
commit
37924c8f63
65
GALAXY_COLLECTIONS_PATH_WARNINGS.patch
Normal file
65
GALAXY_COLLECTIONS_PATH_WARNINGS.patch
Normal file
@ -0,0 +1,65 @@
|
||||
From 734f38b2594692707d1fd3cbcfc8dc8a677f4ee3 Mon Sep 17 00:00:00 2001
|
||||
From: Maxwell G <maxwell@gtmx.me>
|
||||
Date: Fri, 21 Apr 2023 07:29:10 -0500
|
||||
Subject: [PATCH] Add GALAXY_COLLECTIONS_PATH_WARNINGS option. (#78487)
|
||||
|
||||
* Add GALAXY_COLLECTIONS_PATH_WARNING option.
|
||||
|
||||
This allows users to disable warnings from `ansible-galaxy collection
|
||||
install` about `--collections-path` missing from Ansible's configured
|
||||
collections_paths.
|
||||
---
|
||||
.../fragments/78487-galaxy-collections-path-warnings.yml | 6 ++++++
|
||||
lib/ansible/cli/galaxy.py | 5 ++++-
|
||||
lib/ansible/config/base.yml | 9 +++++++++
|
||||
3 files changed, 19 insertions(+), 1 deletion(-)
|
||||
create mode 100644 changelogs/fragments/78487-galaxy-collections-path-warnings.yml
|
||||
|
||||
diff --git a/changelogs/fragments/78487-galaxy-collections-path-warnings.yml b/changelogs/fragments/78487-galaxy-collections-path-warnings.yml
|
||||
new file mode 100644
|
||||
index 00000000000000..4702e94f961d82
|
||||
--- /dev/null
|
||||
+++ b/changelogs/fragments/78487-galaxy-collections-path-warnings.yml
|
||||
@@ -0,0 +1,6 @@
|
||||
+---
|
||||
+minor_changes:
|
||||
+- >-
|
||||
+ Add ``GALAXY_COLLECTIONS_PATH_WARNING`` option to disable the warning
|
||||
+ given by ``ansible-galaxy collection install`` when installing a collection
|
||||
+ to a path that isn't in the configured collection paths.
|
||||
diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py
|
||||
index fc88137ff63604..0deb0331a582b9 100755
|
||||
--- a/lib/ansible/cli/galaxy.py
|
||||
+++ b/lib/ansible/cli/galaxy.py
|
||||
@@ -1393,7 +1393,10 @@ def _execute_install_collection(
|
||||
upgrade = context.CLIARGS.get('upgrade', False)
|
||||
|
||||
collections_path = C.COLLECTIONS_PATHS
|
||||
- if len([p for p in collections_path if p.startswith(path)]) == 0:
|
||||
+ if (
|
||||
+ C.GALAXY_COLLECTIONS_PATH_WARNING
|
||||
+ and len([p for p in collections_path if p.startswith(path)]) == 0
|
||||
+ ):
|
||||
display.warning("The specified collections path '%s' is not part of the configured Ansible "
|
||||
"collections paths '%s'. The installed collection will not be picked up in an Ansible "
|
||||
"run, unless within a playbook-adjacent collections directory." % (to_text(path), to_text(":".join(collections_path))))
|
||||
diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml
|
||||
index 052a8f0834e4ca..206deb76d2e916 100644
|
||||
--- a/lib/ansible/config/base.yml
|
||||
+++ b/lib/ansible/config/base.yml
|
||||
@@ -1366,6 +1366,15 @@ GALAXY_COLLECTION_SKELETON_IGNORE:
|
||||
ini:
|
||||
- {key: collection_skeleton_ignore, section: galaxy}
|
||||
type: list
|
||||
+GALAXY_COLLECTIONS_PATH_WARNING:
|
||||
+ name: "ansible-galaxy collection install colections path warnings"
|
||||
+ description: "whether ``ansible-galaxy collection install`` should warn about ``--collections-path`` missing from configured :ref:`collections_paths`"
|
||||
+ default: true
|
||||
+ type: bool
|
||||
+ env: [{name: ANSIBLE_GALAXY_COLLECTIONS_PATH_WARNING}]
|
||||
+ ini:
|
||||
+ - {key: collections_path_warning, section: galaxy}
|
||||
+ version_added: "2.16"
|
||||
# TODO: unused?
|
||||
#GALAXY_SCMS:
|
||||
# name: Galaxy SCMS
|
@ -15,6 +15,7 @@ Source0: https://github.com/ansible/ansible/archive/v%{uversion}/%{name}-%{uvers
|
||||
Source1: build_manpages.py
|
||||
Patch: https://github.com/ansible/ansible/commit/79751ed970f01ff76270f3dbcae04aa87789eb05.patch#/improve-dnf-version-detection.patch
|
||||
Patch: https://github.com/ansible/ansible/commit/ddf298097c26a855fa58137dba1931c28c4d22aa.patch#/Replace-mock-import-with-compat.mock.patch
|
||||
Patch: https://github.com/ansible/ansible/commit/734f38b2594692707d1fd3cbcfc8dc8a677f4ee3.patch#/GALAXY_COLLECTIONS_PATH_WARNINGS.patch
|
||||
Url: https://ansible.com
|
||||
BuildArch: noarch
|
||||
|
||||
|
54
tests/collections_path_warnings.sh
Executable file
54
tests/collections_path_warnings.sh
Executable file
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
set -xeuo pipefail
|
||||
|
||||
export NO_COLOR=1
|
||||
|
||||
TMP=$(mktemp -d)
|
||||
|
||||
trap "rm -rf $TMP" EXIT
|
||||
|
||||
testcase() {
|
||||
set +x
|
||||
echo
|
||||
echo
|
||||
echo "$1"
|
||||
echo
|
||||
echo
|
||||
set -x
|
||||
}
|
||||
|
||||
fix_log() {
|
||||
tr '\n' ' ' <log | sponge log
|
||||
}
|
||||
|
||||
|
||||
cd $TMP
|
||||
version="0.2.1"
|
||||
git clone https://git.sr.ht/~gotmax23/ansible-collection-epel --branch="v${version}" --depth=1
|
||||
cd ansible-collection-epel
|
||||
mkdir abc
|
||||
ansible-galaxy collection build .
|
||||
|
||||
run="unbuffer ansible-galaxy collection install gotmax23-epel-${version}.tar.gz"
|
||||
warning="The installed collection will not be picked up in an Ansible run"
|
||||
|
||||
testcase "Control: Check plain collection install"
|
||||
${run} |& tee log
|
||||
fix_log
|
||||
(! grep "${warning}" log)
|
||||
|
||||
testcase "Check special collection install"
|
||||
${run} -p abc |& tee log
|
||||
fix_log
|
||||
grep "${warning}" log
|
||||
|
||||
testcase "Check special collection install with option"
|
||||
ANSIBLE_GALAXY_COLLECTIONS_PATH_WARNING=1 ${run} -p abc |& tee log
|
||||
fix_log
|
||||
grep "${warning}" log
|
||||
|
||||
testcase "Check special collection install without option"
|
||||
ANSIBLE_GALAXY_COLLECTIONS_PATH_WARNING=0 ${run} -p abc |& tee log
|
||||
fix_log
|
||||
(! grep "${warning}" log)
|
16
tests/fedora.fmf
Normal file
16
tests/fedora.fmf
Normal file
@ -0,0 +1,16 @@
|
||||
summary: A set of Fedora specific ansible integration tests
|
||||
discover:
|
||||
- name: Generic ansible integration tests
|
||||
how: shell
|
||||
tests:
|
||||
- name: Run tests/collections_path_warnings.sh
|
||||
summary: Ensure GALAXY_COLLECTIONS_PATH_WARNINGS works properly
|
||||
test: tests/collections_path_warnings.sh
|
||||
require:
|
||||
- ansible-core
|
||||
- git-core
|
||||
- python3-distlib
|
||||
- /usr/bin/sponge
|
||||
- /usr/bin/unbuffer
|
||||
execute:
|
||||
how: tmt
|
Loading…
Reference in New Issue
Block a user