From 24d91f552cad2a485f286f3c34cbba2005599ab4 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Wed, 15 Jun 2022 14:41:04 -0700 Subject: [PATCH] ansible-test - Add support for more remotes. --- .../fragments/ansible-test-more-remotes.yml | 5 + .../ansible_test/_data/completion/remote.txt | 6 ++ test/lib/ansible_test/_internal/become.py | 19 ++++ .../_util/target/setup/bootstrap.sh | 101 ++++++++++++++++-- 4 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/ansible-test-more-remotes.yml diff --git a/changelogs/fragments/ansible-test-more-remotes.yml b/changelogs/fragments/ansible-test-more-remotes.yml new file mode 100644 index 00000000000..6ac97de5da6 --- /dev/null +++ b/changelogs/fragments/ansible-test-more-remotes.yml @@ -0,0 +1,5 @@ +minor_changes: + - ansible-test - Add support for provisioning remotes which require ``doas`` for become. + - ansible-test - Add support for provisioning Ubuntu 20.04 remote instances. + - ansible-test - Add support for provisioning Alpine 3.16 remote instances. + - ansible-test - Add support for provisioning Fedora 35 and 36 remote instances. diff --git a/test/lib/ansible_test/_data/completion/remote.txt b/test/lib/ansible_test/_data/completion/remote.txt index d9738d36473..afd64d8215d 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 3218b24d613..25df71089f5 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 58e82953343..128ed094c26 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 ;;