From 00bb4c7198002255e1014b21c3e00654ebf094a7 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Tue, 18 Jun 2024 09:13:42 +0200 Subject: [PATCH] tests: containerize vagrant commands with podman Added a function to wrap vagrant commands within a podman container Signed-off-by: Guillaume Abrioux --- tests/scripts/generate_ssh_config.sh | 3 +++ tests/scripts/vagrant.sh | 18 ++++++++++++++++++ tests/scripts/vagrant_up.sh | 25 ++++++++++++++++--------- 3 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 tests/scripts/vagrant.sh diff --git a/tests/scripts/generate_ssh_config.sh b/tests/scripts/generate_ssh_config.sh index feebaf676c..6b105ab876 100644 --- a/tests/scripts/generate_ssh_config.sh +++ b/tests/scripts/generate_ssh_config.sh @@ -2,6 +2,9 @@ # Generate a custom ssh config from Vagrant so that it can then be used by # ansible.cfg +p=$(readlink -f $(dirname $0)) +source "${p}/vagrant.sh" + path=$1 if [ $# -eq 0 ] diff --git a/tests/scripts/vagrant.sh b/tests/scripts/vagrant.sh new file mode 100644 index 0000000000..02b1ffb716 --- /dev/null +++ b/tests/scripts/vagrant.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +vagrant(){ + root_dir=$(realpath "${PWD}/Vagrantfile") + podman run --rm \ + -e LIBVIRT_DEFAULT_URI \ + -e SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" \ + -v /var/run/libvirt/:/var/run/libvirt/ \ + -v ~/.vagrant.d:/.vagrant.d \ + -v $(realpath "${PWD}"):${PWD} \ + -v "${root_dir}:${root_dir}" \ + -w "${PWD}" \ + --network host \ + --entrypoint vagrant \ + --security-opt label=disable \ + docker.io/vagrantlibvirt/vagrant-libvirt:latest \ + $@ +} diff --git a/tests/scripts/vagrant_up.sh b/tests/scripts/vagrant_up.sh index 05b17582f4..9184db3854 100644 --- a/tests/scripts/vagrant_up.sh +++ b/tests/scripts/vagrant_up.sh @@ -1,5 +1,11 @@ #!/bin/bash set -x + +p=$(readlink -f $(dirname $0)) +source "${p}/vagrant.sh" + +test -d ~/.vagrant.d || mkdir ~/.vagrant.d + if [[ -n $1 ]]; then DIRECTORY=$1 shift @@ -15,14 +21,15 @@ if [[ "${CEPH_ANSIBLE_VAGRANT_BOX}" =~ "centos/stream" ]]; then vagrant box add --force --provider libvirt --name "${CEPH_ANSIBLE_VAGRANT_BOX}" "https://cloud.centos.org/centos/${EL_VERSION}-stream/x86_64/images/${LATEST_IMAGE}" --force fi -retries=0 -until [ $retries -ge 5 ] -do - echo "Attempting to start VMs. Attempts: $retries" - timeout 10m time vagrant up "$@" && break - retries=$((retries+1)) - sleep 5 -done +vagrant up "$@" +#retries=0 +#until [ $retries -ge 5 ] +#do +# echo "Attempting to start VMs. Attempts: $retries" +# timeout 10m time vagrant up "$@" && break +# retries=$((retries+1)) +# sleep 5 +#done -sleep 10 +#sleep 10 popd