Notification time stamped 2022-09-30 21:11:11 UTC
From f9f014a54d4f818097949a9e41bf0a7a80b61062 Mon Sep 17 00:00:00 2001
From: Maxwell G <gotmax(a)e.email>
Date: Sep 30 2022 20:51:12 +0000
Subject: Only build against ansible-core
We want the newest ansible-test, and we may add other macros that
require the newest version. The generated runtime Requires remain the
same.
https://src.fedoraproject.org/rpms/ansible/c/f246aba7759fd8ea181333fa827d9b…
makes this okay to reapply to F35.
---
diff --git a/ansible-packaging.spec b/ansible-packaging.spec
index 6a2b6f9..d769013 100644
--- a/ansible-packaging.spec
+++ b/ansible-packaging.spec
@@ -11,9 +11,9 @@ Source2: macros.ansible
Source3: macros.ansible-srpm
Source4: COPYING
-# Require either ansible-core or a version of ansible 2.9 that supports collections but prefer ansible-core.
-Requires: (ansible-core or (ansible < 2.10.0 with ansible >= 2.9.10))
-Suggests: ansible-core
+# Require ansible-core for building. Collections still have a boolean runtime
+# dependency on either ansible 2.9 OR ansible-core.
+Requires: ansible-core
Requires: ansible-srpm-macros = %{version}-%{release}
@@ -38,8 +38,6 @@ Summary: SRPM stage RPM packaging macros for Ansible collections
%package tests
Summary: Dependencies for Ansible collection package unit tests
Requires: %{name} = %{version}-%{release}
-# Unit tests use ansible-core not ansible 2.9.
-Requires: ansible-core
Requires: /usr/bin/ansible-test
# This list is taken from %%{python3_sitelib}/ansible_test/_data/requirements/units.txt
Requires: %{py3_dist pytest}
https://src.fedoraproject.org/rpms/ansible-packaging/c/f9f014a54d4f81809794…
Notification time stamped 2022-09-30 21:11:11 UTC
From c67bd58e7937afa0cff3e9ce94e4d5d3a3a14a3d Mon Sep 17 00:00:00 2001
From: Maxwell G <gotmax(a)e.email>
Date: Sep 30 2022 20:33:25 +0000
Subject: %ansible_collection_url: Don't require control macros
Reimplement %ansible_collection_url to accept the collection namespace
and name as arguments instead of requiring oblique control macros. This
also adds some basic tests to ensure that the macro behaves properly.
---
diff --git a/ansible-packaging.spec b/ansible-packaging.spec
index 4e2478c..26b648f 100644
--- a/ansible-packaging.spec
+++ b/ansible-packaging.spec
@@ -77,6 +77,57 @@ install -Dpm0644 -t %{buildroot}%{_rpmmacrodir} macros.ansible-srpm
install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} ansible-generator
install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} ansible_collection.py
+%check
+# TODO: Currently, this only tests %%{ansible_collection_url}.
+
+rpm_eval() {
+ default_macros_path="$(rpm --showrc | grep 'Macro path' | awk -F ': ' '{print $2}')"
+ rpm --macros="${default_macros_path}:%{buildroot}%{_rpmmacrodir}/macros.*" "$@"
+}
+
+errors() {
+ error="error: %%ansible_collection_url: You must pass the collection namespace as the first arg and the collection name as the second"
+ "$@" && exit 1
+ "$@" |& grep -q "${error}"
+}
+
+echo "Ensure macro fails when only collection_namespace macro is defined"
+errors rpm_eval -D 'collection_namespace cc' -E '%%ansible_collection_url'
+
+echo
+echo "Ensure macro fails when only collection_name macro is defined"
+errors rpm_eval -D 'collection_name cc' -E '%%ansible_collection_url'
+
+echo
+echo "Ensure macro fails when second argument is missing"
+errors rpm_eval -E '%%ansible_collection_url a'
+
+echo
+echo "Ensure macro fails when second argument is missing"
+errors rpm_eval -D 'collection_name b' -E '%%ansible_collection_url a'
+
+echo
+echo "Ensure macro fails when neither the control macros nor macro arguments are passed"
+errors rpm_eval -E '%%ansible_collection_url'
+
+
+echo
+echo
+echo "Ensure macro works when both arguments are passed and no control macros are set"
+[[ $(rpm_eval -E '%%ansible_collection_url community general') == \
+ "https://galaxy.ansible.com/community/general" ]]
+
+echo
+echo "Ensure macro works with the control macros"
+[[ $(rpm_eval -D 'collection_namespace ansible' -D 'collection_name posix' \
+ -E '%%ansible_collection_url') == "https://galaxy.ansible.com/ansible/posix" ]]
+
+echo
+echo "Ensure macro prefers the collection namespace and name passed as an argument over the control macros"
+[[ $(rpm_eval -D 'collection_namespace ansible' -D 'collection_name posix' \
+ -E '%%ansible_collection_url community general') == "https://galaxy.ansible.com/community/general" ]]
+
+
%files
%license COPYING
diff --git a/macros.ansible-srpm b/macros.ansible-srpm
index 9b208b4..0adacd7 100644
--- a/macros.ansible-srpm
+++ b/macros.ansible-srpm
@@ -1 +1,25 @@
-%ansible_collection_url() https://galaxy.ansible.com/%{collection_namespace}/%{collection_name}
+# Note(gotmax23): I'm trying to get rid of the need for control macros in favor
+# of a metadata based approach. %%ansible_collection_url is the only macro that
+# requires manually specifying the collection namespace and name, as it is used
+# at the SRPM build stage.
+#
+# Currently, this macro supports either passing this information as arguments
+# or defining the control macros. In order to reduce confusion, this is not an
+# either or approach. Both arguments must be passed OR both control macros must
+# be defined.
+
+%ansible_collection_url() %{lua:
+ local namespace_name = nil
+ if rpm.expand("%collection_namespace") ~= "%collection_namespace"
+ and rpm.expand("%collection_name") ~= "%collection_name" then
+ namespace_name = rpm.expand("%collection_namespace") .. "/" .. rpm.expand("%collection_name")
+ end
+ if rpm.expand("%1") ~= "%1" and rpm.expand("%2") ~= "%2" then
+ namespace_name = rpm.expand("%1") .. "/" .. rpm.expand("%2")
+ end
+ if not namespace_name then
+ rpm.expand("%{error:%%ansible_collection_url: You must pass the collection " ..
+ "namespace as the first arg and the collection name as the second}")
+ end
+ print("https://galaxy.ansible.com/" .. namespace_name)
+}
https://src.fedoraproject.org/rpms/ansible-packaging/c/c67bd58e7937afa0cff3…
Notification time stamped 2022-09-30 21:11:11 UTC
From e3d150ec904179fd2d529763491692ee3b192c44 Mon Sep 17 00:00:00 2001
From: Maxwell G <gotmax(a)e.email>
Date: Sep 30 2022 20:14:22 +0000
Subject: Flush stdout before subprocess.run
This commit adds sys.stdout.flush() before subprocess.run() in
ansible_collection.py. Without this, the print statements are shown
after the command output when building in mock.
---
diff --git a/ansible_collection.py b/ansible_collection.py
index 17c6777..70093be 100755
--- a/ansible_collection.py
+++ b/ansible_collection.py
@@ -70,6 +70,9 @@ class AnsibleCollection:
)
print(f"Running: {args}")
print()
+ # Without this, the print statements are shown after the command
+ # output when building in mock.
+ sys.stdout.flush()
subprocess.run(args, check=True, cwd=self.collection_srcdir)
print()
@@ -90,6 +93,9 @@ class AnsibleCollection:
args = ("ansible-test", "units", *extra_args)
print(f"Running: {args}")
print()
+ # Without this, the print statements are shown after the command
+ # output when building in mock.
+ sys.stdout.flush()
subprocess.run(args, cwd=temppath, check=True)
https://src.fedoraproject.org/rpms/ansible-packaging/c/e3d150ec904179fd2d52…
Notification time stamped 2022-09-30 21:11:11 UTC
From b1de39d9c64cabf7c40c29d445e135b0e41a3f0b Mon Sep 17 00:00:00 2001
From: Maxwell G <gotmax(a)e.email>
Date: Sep 26 2022 04:07:27 +0000
Subject: Add new %ansible_collection_filelist macro
%ansible_collection_files cannot be adapted to dynamically determine the
collection namespace. We need to use a file list for that.
%ansible_collection_install writes out a file list to
%ansible_collection_filelist. Packagers would pass
`%{ansible_collection_filelist}` to `%files -f`.
Eventually, I'd like to deprecate %ansible_collection_files. That won't
happen until the new approach has gotten more testing and adoption.
---
diff --git a/macros.ansible b/macros.ansible
index 0c81432..57c89fe 100644
--- a/macros.ansible
+++ b/macros.ansible
@@ -18,5 +18,11 @@
--python-interpreter %{__python3} --local %{?*}
}
+# TODO: Officially deprecate this macro and add the following line to the macro
+# def after the new approach has gotten more testing and adoption:
+# %%{warn: %%{ansible_collection_files} is deprecated. Use %%files -f %%{ansible_collection_filelist} instead.}
+%ansible_collection_files %{shrink:
+%{ansible_collections_dir}/%{collection_namespace}/
+}
-%ansible_collection_files %{_datadir}/ansible/collections/ansible_collections/%{collection_namespace}/
+%ansible_collection_filelist %{__ansible_builddir}/ansible_collection_files
https://src.fedoraproject.org/rpms/ansible-packaging/c/b1de39d9c64cabf7c40c…
Notification time stamped 2022-09-30 21:11:11 UTC
From 78dcf4c992c5c3189675c7f579864c9140cf5898 Mon Sep 17 00:00:00 2001
From: Maxwell G <gotmax(a)e.email>
Date: Sep 26 2022 04:07:27 +0000
Subject: Outsource %ansible_test_unit logic to helper script
We want %ansible_test_unit to retrieve the collection name{,space} from
galaxy.yml. This removes the need for the %collection_name{,space}
macros and utilizes ansible_collection.py's more robust approach to
running the tests.
---
diff --git a/macros.ansible b/macros.ansible
index 856688e..0c81432 100644
--- a/macros.ansible
+++ b/macros.ansible
@@ -13,12 +13,10 @@
--filelist %{ansible_collection_filelist}
}
+%ansible_test_unit() %{shrink:
+%{_rpmconfigdir}/ansible_collection.py test --
+--python-interpreter %{__python3} --local %{?*}
+}
-%ansible_test_unit() %{expand:\\\
-mkdir -p ../ansible_collections/%{collection_namespace}
-cp -a $(pwd) ../ansible_collections/%{collection_namespace}/%{collection_name}
-pushd ../ansible_collections/%{collection_namespace}/%{collection_name}
-ansible-test units --python-interpreter %{__python3} --local %{?*}
-popd}
%ansible_collection_files %{_datadir}/ansible/collections/ansible_collections/%{collection_namespace}/
https://src.fedoraproject.org/rpms/ansible-packaging/c/78dcf4c992c5c3189675…
Notification time stamped 2022-09-30 21:11:11 UTC
From 2f4f3dbe16c97231a99c1f0b7305846609058c93 Mon Sep 17 00:00:00 2001
From: Maxwell G <gotmax(a)e.email>
Date: Sep 23 2022 23:00:58 +0000
Subject: Add %ansible_roles_dir and %ansible_collections_dir
We expect collections to use %ansible_collection_install and
%ansible_collection_file{s,list}. I'm mainly defining
%ansible_collection_dir for use in our macros.
There are a couple packaged roles in Fedora that can use
%ansible_roles_dir. This can also be used if we decide to implement
macros for packaging roles.
---
diff --git a/macros.ansible b/macros.ansible
index abab21d..5e2bc06 100644
--- a/macros.ansible
+++ b/macros.ansible
@@ -1,3 +1,6 @@
+%ansible_roles_dir %{_datadir}/ansible/roles
+%ansible_collections_dir %{_datadir}/ansible/collections/ansible_collections
+
%ansible_collection_build() ansible-galaxy collection build
%ansible_collection_install() ansible-galaxy collection install -n -p %{buildroot}%{_datadir}/ansible/collections %{collection_namespace}-%{collection_name}-%{version}.tar.gz
https://src.fedoraproject.org/rpms/ansible-packaging/c/2f4f3dbe16c97231a99c…