From 1555132d85cdd9e5acf4b0ada6d4513d66dab635 Mon Sep 17 00:00:00 2001
From: Rafael Guterres Jeffman <rjeffman@dantooine.home.farrapos.net.br>
Date: Sat, 15 Jul 2023 14:55:44 -0300
Subject: [PATCH] utils/run-tests.sh: Install Ansible collections on virtual
 environment

When runing tests using 'utils/run-tests.sh' from inside an existing
Python virtual environment the Ansible collections are not installed due
to the order of execution of the script. On a machine that does not have
the 'containers.*' collection the test fails as there is no container
connector available.

This patch moves the section that installs Ansible collections to run
after the virtual environment is configured, and then install the
collections (usually, only 'containers.podman'), allowing the tests to
be executed.
---
 utils/run-tests.sh | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/utils/run-tests.sh b/utils/run-tests.sh
index 5852780f..fe1eb720 100755
--- a/utils/run-tests.sh
+++ b/utils/run-tests.sh
@@ -259,17 +259,18 @@ then
     log info "Installing Ansible: ${ANSIBLE_VERSION}"
     pip install --quiet "${ANSIBLE_VERSION}"
     log debug "Ansible version: $(ansible --version | sed -n "1p")${RST}"
-    if [ -n "${ANSIBLE_COLLECTIONS}" ]
-    then
-        log warn "Installed collections will not be removed after execution."
-        log none "Installing: Ansible Collection ${ANSIBLE_COLLECTIONS}"
-        # shellcheck disable=SC2086
-        quiet ansible-galaxy collection install ${ANSIBLE_COLLECTIONS} || die "Failed to install Ansible collections."
-    fi
 else
    log info "Using current virtual environment."
 fi
 
+if [ -n "${ANSIBLE_COLLECTIONS}" ]
+then
+    log warn "Installed collections will not be removed after execution."
+    log none "Installing: Ansible Collection ${ANSIBLE_COLLECTIONS}"
+    # shellcheck disable=SC2086
+    quiet ansible-galaxy collection install ${ANSIBLE_COLLECTIONS} || die "Failed to install Ansible collections."
+fi
+
 # Ansible configuration
 export ANSIBLE_ROLES_PATH="${TOPDIR}/roles"
 export ANSIBLE_LIBRARY="${TOPDIR}/plugins:${TOPDIR}/molecule"
-- 
GitLab