summaryrefslogtreecommitdiffstats
path: root/test/lib/ansible_test
diff options
context:
space:
mode:
authorMatt Clay <matt@mystile.com>2022-06-15 23:41:04 +0200
committerMatt Clay <matt@mystile.com>2022-06-18 03:56:06 +0200
commit24d91f552cad2a485f286f3c34cbba2005599ab4 (patch)
tree6cee78cd90102487dd9312b72ffce8cbcf94ebdf /test/lib/ansible_test
parentansible-test - More flexible become support. (diff)
downloadansible-24d91f552cad2a485f286f3c34cbba2005599ab4.tar.xz
ansible-24d91f552cad2a485f286f3c34cbba2005599ab4.zip
ansible-test - Add support for more remotes.
Diffstat (limited to 'test/lib/ansible_test')
-rw-r--r--test/lib/ansible_test/_data/completion/remote.txt6
-rw-r--r--test/lib/ansible_test/_internal/become.py19
-rw-r--r--test/lib/ansible_test/_util/target/setup/bootstrap.sh101
3 files changed, 117 insertions, 9 deletions
diff --git a/test/lib/ansible_test/_data/completion/remote.txt b/test/lib/ansible_test/_data/completion/remote.txt
index d9738d3647..afd64d8215 100644
--- a/test/lib/ansible_test/_data/completion/remote.txt
+++ b/test/lib/ansible_test/_data/completion/remote.txt
@@ -1,3 +1,8 @@
+alpine/3.16 python=3.10 become=doas provider=aws arch=x86_64
+alpine become=doas provider=aws arch=x86_64
+fedora/35 python=3.10 become=sudo provider=aws arch=x86_64
+fedora/36 python=3.10 become=sudo provider=aws arch=x86_64
+fedora become=sudo provider=aws arch=x86_64
freebsd/12.3 python=3.8 python_dir=/usr/local/bin become=su provider=aws arch=x86_64
freebsd/13.0 python=3.7,3.8,3.9 python_dir=/usr/local/bin become=su provider=aws arch=x86_64
freebsd/13.1 python=3.8,3.7,3.9,3.10 python_dir=/usr/local/bin become=su provider=aws arch=x86_64
@@ -9,5 +14,6 @@ rhel/8.5 python=3.6,3.8,3.9 become=sudo provider=aws arch=x86_64
rhel/8.6 python=3.6,3.8,3.9 become=sudo provider=aws arch=x86_64
rhel/9.0 python=3.9 become=sudo provider=aws arch=x86_64
rhel become=sudo provider=aws arch=x86_64
+ubuntu/20.04 python=3.8,3.9 become=sudo provider=aws arch=x86_64
ubuntu/22.04 python=3.10 become=sudo provider=aws arch=x86_64
ubuntu become=sudo provider=aws arch=x86_64
diff --git a/test/lib/ansible_test/_internal/become.py b/test/lib/ansible_test/_internal/become.py
index 3218b24d61..25df71089f 100644
--- a/test/lib/ansible_test/_internal/become.py
+++ b/test/lib/ansible_test/_internal/become.py
@@ -22,6 +22,25 @@ class Become(metaclass=abc.ABCMeta):
"""Return the given command, if any, with privilege escalation."""
+class Doas(Become):
+ """Become using 'doas'."""
+ @property
+ def method(self): # type: () -> str
+ """The name of the Ansible become plugin that is equivalent to this."""
+ raise NotImplementedError('Ansible has no built-in doas become plugin.')
+
+ def prepare_command(self, command): # type: (t.List[str]) -> t.List[str]
+ """Return the given command, if any, with privilege escalation."""
+ become = ['doas', '-n']
+
+ if command:
+ become.extend(['sh', '-c', ' '.join(shlex.quote(c) for c in command)])
+ else:
+ become.extend(['-s'])
+
+ return become
+
+
class Su(Become):
"""Become using 'su'."""
@property
diff --git a/test/lib/ansible_test/_util/target/setup/bootstrap.sh b/test/lib/ansible_test/_util/target/setup/bootstrap.sh
index 58e8295334..128ed094c2 100644
--- a/test/lib/ansible_test/_util/target/setup/bootstrap.sh
+++ b/test/lib/ansible_test/_util/target/setup/bootstrap.sh
@@ -80,6 +80,66 @@ pip_install() {
done
}
+bootstrap_remote_alpine()
+{
+ py_pkg_prefix="py3"
+
+ packages="
+ bash
+ gcc
+ python3-dev
+ ${py_pkg_prefix}-pip
+ "
+
+ if [ "${controller}" ]; then
+ packages="
+ ${packages}
+ ${py_pkg_prefix}-cryptography
+ ${py_pkg_prefix}-packaging
+ ${py_pkg_prefix}-yaml
+ ${py_pkg_prefix}-jinja2
+ ${py_pkg_prefix}-resolvelib
+ "
+ fi
+
+ while true; do
+ # shellcheck disable=SC2086
+ apk add -q ${packages} \
+ && break
+ echo "Failed to install packages. Sleeping before trying again..."
+ sleep 10
+ done
+}
+
+bootstrap_remote_fedora()
+{
+ py_pkg_prefix="python3"
+
+ packages="
+ gcc
+ ${py_pkg_prefix}-devel
+ "
+
+ if [ "${controller}" ]; then
+ packages="
+ ${packages}
+ ${py_pkg_prefix}-cryptography
+ ${py_pkg_prefix}-jinja2
+ ${py_pkg_prefix}-packaging
+ ${py_pkg_prefix}-pyyaml
+ ${py_pkg_prefix}-resolvelib
+ "
+ fi
+
+ while true; do
+ # shellcheck disable=SC2086
+ dnf install -q -y ${packages} \
+ && break
+ echo "Failed to install packages. Sleeping before trying again..."
+ sleep 10
+ done
+}
+
bootstrap_remote_freebsd()
{
packages="
@@ -271,21 +331,42 @@ bootstrap_remote_ubuntu()
packages="
gcc
- ${py_pkg_prefix}-dev
- ${py_pkg_prefix}-pip
- ${py_pkg_prefix}-venv
+ python${python_version}-dev
+ python3-pip
+ python${python_version}-venv
"
if [ "${controller}" ]; then
- # The resolvelib package is not listed here because the available version (0.8.1) is incompatible with ansible.
- # Instead, ansible-test will install it using pip.
+ cryptography_pkg="${py_pkg_prefix}-cryptography"
+ jinja2_pkg="${py_pkg_prefix}-jinja2"
+ packaging_pkg="${py_pkg_prefix}-packaging"
+ pyyaml_pkg="${py_pkg_prefix}-yaml"
+ resolvelib_pkg="${py_pkg_prefix}-resolvelib"
+
+ # Declare platforms which do not have supporting OS packages available.
+ # For these ansible-test will use pip to install the requirements instead.
+ # Only the platform is checked since Ubuntu shares Python packages across Python versions.
+ case "${platform_version}" in
+ "20.04")
+ jinja2_pkg="" # too old
+ resolvelib_pkg="" # not available
+ ;;
+ esac
+
packages="
${packages}
- ${py_pkg_prefix}-cryptography
- ${py_pkg_prefix}-jinja2
- ${py_pkg_prefix}-packaging
- ${py_pkg_prefix}-yaml
+ ${cryptography_pkg}
+ ${jinja2_pkg}
+ ${packaging_pkg}
+ ${pyyaml_pkg}
+ ${resolvelib_pkg}
"
+
+ if [ "${platform_version}/${python_version}" = "20.04/3.9" ]; then
+ # Install pyyaml using pip so libyaml support is available on Python 3.9.
+ # The OS package install (which is installed by default) only has a .so file for Python 3.8.
+ pip_install "--upgrade pyyaml"
+ fi
fi
while true; do
@@ -313,6 +394,8 @@ bootstrap_remote()
python_package_version="$(echo "${python_version}" | tr -d '.')"
case "${platform}" in
+ "alpine") bootstrap_remote_alpine ;;
+ "fedora") bootstrap_remote_fedora ;;
"freebsd") bootstrap_remote_freebsd ;;
"macos") bootstrap_remote_macos ;;
"rhel") bootstrap_remote_rhel ;;