From a47a334b21c2d64cc0580f702e62c3bdca7f55b8 Mon Sep 17 00:00:00 2001 From: Andrii Nikitin Date: Thu, 16 May 2024 14:32:59 +0200 Subject: [PATCH 1/2] ci: Use podman for container tests Docker has complications running systemd inside container --- .circleci/config.yml | 15 --------------- .github/workflows/integration.yaml | 14 ++++++++++++++ t/{docker => podman}/lib/common.sh | 14 +++++++++++--- .../lib/test-in-container-systemd.sh | 18 +++++++++--------- t/{docker => podman}/rest.sh | 0 t/{docker => podman}/rsync.sh | 0 .../script/openSUSE:Factory:ToTest.sh | 14 +++++++++----- .../script/openSUSE:Leap:15.2:ARM:ToTest.sh | 0 .../script/openSUSE:Leap:15.2:Staging:A.sh | 0 .../script/openSUSE:Leap:15.4:WSL.sh | 0 t/run_docker.sh | 2 +- 11 files changed, 44 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/integration.yaml rename t/{docker => podman}/lib/common.sh (94%) rename t/{docker => podman}/lib/test-in-container-systemd.sh (69%) rename t/{docker => podman}/rest.sh (100%) rename t/{docker => podman}/rsync.sh (100%) rename t/{docker => podman}/script/openSUSE:Factory:ToTest.sh (97%) rename t/{docker => podman}/script/openSUSE:Leap:15.2:ARM:ToTest.sh (100%) rename t/{docker => podman}/script/openSUSE:Leap:15.2:Staging:A.sh (100%) rename t/{docker => podman}/script/openSUSE:Leap:15.4:WSL.sh (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9df059d7..a495dacc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,24 +25,9 @@ jobs: - checkout - run: make test_python_style - - integration: - machine: - image: ubuntu-2004:202201-02 - steps: - - checkout - - run: - command: | - pyenv versions - pyenv global 3.10.2 - docker pull registry.opensuse.org/devel/openqa/ci/containers/serviced - sudo chown -R 1000:1000 . - make test_docker PRIVILEGED_TESTS=1 - workflows: version: 2.1 test: jobs: - unit - - integration - style diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml new file mode 100644 index 00000000..8f6de089 --- /dev/null +++ b/.github/workflows/integration.yaml @@ -0,0 +1,14 @@ +--- +name: CI + +on: [pull_request, workflow_dispatch] # yamllint disable-line rule:truthy + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: integration + run: | + podman pull registry.opensuse.org/devel/openqa/ci/containers/serviced + make test_docker PRIVILEGED_TESTS=1 diff --git a/t/docker/lib/common.sh b/t/podman/lib/common.sh similarity index 94% rename from t/docker/lib/common.sh rename to t/podman/lib/common.sh index a6872347..55d3112d 100644 --- a/t/docker/lib/common.sh +++ b/t/podman/lib/common.sh @@ -5,16 +5,23 @@ prepare_project() { prj=$1 suff=$2 -su $dbuser -c "set -ex +( cd /opt/openqa-trigger-from-obs mkdir -p $prj +chown $dbuser $prj +echo geekotest > rsync.secret +chmod 600 rsync.secret +chown $dbuser rsync.secret +) + +su $dbuser -c "set -ex +cd /opt/openqa-trigger-from-obs python3 script/scriptgen.py $prj for l in $prj/*/.run_last ; do [ ! -e \$l ] || rm \$l done [ ! -e $prj/.run_last ] || rm $prj/.run_last -echo geekotest > rsync.secret -chmod 600 rsync.secret" +" echo "[production] dsn = DBI:Pg:dbname=openqa;host=/tmp" > /usr/share/openqa/etc/openqa/database.ini @@ -28,6 +35,7 @@ chmod +x /var/lib/openqa/osc-plugin-factory/factory-package-news/factory-package systemctl start postgresql +systemctl restart apache2 systemctl restart openqa-webui.service systemctl restart openqa-websockets.service systemctl restart rsyncd diff --git a/t/docker/lib/test-in-container-systemd.sh b/t/podman/lib/test-in-container-systemd.sh similarity index 69% rename from t/docker/lib/test-in-container-systemd.sh rename to t/podman/lib/test-in-container-systemd.sh index 798c4ca4..5afb1e92 100755 --- a/t/docker/lib/test-in-container-systemd.sh +++ b/t/podman/lib/test-in-container-systemd.sh @@ -29,11 +29,11 @@ containername="localtest.${basename,,}" test "${PRIVILEGED_TESTS}" == 1 || ( echo PRIVILEGED_TESTS is not set to 1 ; exit 1) -docker info >/dev/null 2>&1 || (echo Docker doesnt seem to be running ; exit 1) +podman info >/dev/null 2>&1 || (echo podman doesnt seem to be running ; exit 1) map_port="" [ -z "$EXPOSE_PORT" ] || map_port="-p $EXPOSE_PORT:80" -docker run --privileged $map_port -v"$thisdir/../../..":/opt/openqa-trigger-from-obs --env METHOD=$METHOD --rm --name "$containername" -d -v /sys/fs/cgroup:/sys/fs/cgroup:ro -- registry.opensuse.org/devel/openqa/ci/containers/serviced +podman run --privileged $map_port -v"$thisdir/../../..":/opt/openqa-trigger-from-obs:z --env METHOD=$METHOD --rm --name "$containername" -d -- registry.opensuse.org/devel/openqa/ci/containers/serviced in_cleanup=0 @@ -44,7 +44,7 @@ function cleanup { read -rsn1 -p"Test failed, press any key to finish";echo fi [ "$ret" == 0 ] || echo FAIL $basename - docker stop -t 0 "$containername" >&/dev/null || : + podman stop -t 0 "$containername" >&/dev/null || : } trap cleanup INT TERM EXIT @@ -53,17 +53,17 @@ counter=1 # wait container start until [ $counter -gt 10 ]; do sleep 0.5 - docker exec "$containername" pwd >& /dev/null && break + podman exec "$containername" pwd >& /dev/null && break ((counter++)) done -docker exec "$containername" pwd >& /dev/null || (echo Cannot start container; exit 1 ) >&2 +podman exec "$containername" pwd >& /dev/null || (echo Cannot start container; exit 1 ) >&2 -docker exec "$containername" bash /opt/init-trigger-from-obs.sh +podman exec "$containername" bash /opt/init-trigger-from-obs.sh -[ -z "$CIRCLE_JOB" ] || echo 'aa-complain /usr/share/openqa/script/openqa' | docker exec "$containername" bash -x +[ -z "$CIRCLE_JOB" ] || echo 'aa-complain /usr/share/openqa/script/openqa' | podman exec "$containername" bash -x set +e -docker cp lib/common.sh "$containername":/lib -docker exec -e TESTCASE="$testcase" "$containername" bash -xe /opt/openqa-trigger-from-obs/t/docker/$testcase +podman cp lib/common.sh "$containername":/lib +podman exec -e TESTCASE="$testcase" "$containername" bash -xe /opt/openqa-trigger-from-obs/t/podman/$testcase ret=$? ( exit $ret ) diff --git a/t/docker/rest.sh b/t/podman/rest.sh similarity index 100% rename from t/docker/rest.sh rename to t/podman/rest.sh diff --git a/t/docker/rsync.sh b/t/podman/rsync.sh similarity index 100% rename from t/docker/rsync.sh rename to t/podman/rsync.sh diff --git a/t/docker/script/openSUSE:Factory:ToTest.sh b/t/podman/script/openSUSE:Factory:ToTest.sh similarity index 97% rename from t/docker/script/openSUSE:Factory:ToTest.sh rename to t/podman/script/openSUSE:Factory:ToTest.sh index 80780af8..dcf910cd 100755 --- a/t/docker/script/openSUSE:Factory:ToTest.sh +++ b/t/podman/script/openSUSE:Factory:ToTest.sh @@ -28,14 +28,18 @@ echo 1 > /mockOBS/openSUSE\:Factory\:ToTest/images/local/000product:openSUSE-Add # create just empty files as at this point we are not interested about proper binaries chown -R "$dbuser" /mockOBS - -su $dbuser -c 'set -ex +( cd /opt/openqa-trigger-from-obs mkdir -p openSUSE:Factory:ToTest -python3 script/scriptgen.py openSUSE:Factory:ToTest -[ ! -e openSUSE:Factory:ToTest/base/.run_last ] || rm openSUSE:Factory:ToTest/base/.run_last echo geekotest > rsync.secret -chmod 600 rsync.secret' +chmod 600 rsync.secret +chown geekotest rsync.secret +) + +su $dbuser -c 'set -ex +cd /opt/openqa-trigger-from-obs +python3 script/scriptgen.py openSUSE:Factory:ToTest +[ ! -e openSUSE:Factory:ToTest/base/.run_last ] || rm openSUSE:Factory:ToTest/base/.run_last' echo '127.0.0.1 obspublish' >> /etc/hosts systemctl enable --now postgresql diff --git a/t/docker/script/openSUSE:Leap:15.2:ARM:ToTest.sh b/t/podman/script/openSUSE:Leap:15.2:ARM:ToTest.sh similarity index 100% rename from t/docker/script/openSUSE:Leap:15.2:ARM:ToTest.sh rename to t/podman/script/openSUSE:Leap:15.2:ARM:ToTest.sh diff --git a/t/docker/script/openSUSE:Leap:15.2:Staging:A.sh b/t/podman/script/openSUSE:Leap:15.2:Staging:A.sh similarity index 100% rename from t/docker/script/openSUSE:Leap:15.2:Staging:A.sh rename to t/podman/script/openSUSE:Leap:15.2:Staging:A.sh diff --git a/t/docker/script/openSUSE:Leap:15.4:WSL.sh b/t/podman/script/openSUSE:Leap:15.4:WSL.sh similarity index 100% rename from t/docker/script/openSUSE:Leap:15.4:WSL.sh rename to t/podman/script/openSUSE:Leap:15.4:WSL.sh diff --git a/t/run_docker.sh b/t/run_docker.sh index 5335e7ba..bbd25282 100644 --- a/t/run_docker.sh +++ b/t/run_docker.sh @@ -2,7 +2,7 @@ cd "$(dirname "${BASH_SOURCE[0]}")" ( dockerfail=0 -cd docker +cd podman for t in *.sh; do [ -x "$t" ] || continue for i in $(seq 1 3); do From a5b0ff702ad9a451b4d50ca3f82db94216789192 Mon Sep 17 00:00:00 2001 From: Andrii Nikitin Date: Thu, 16 May 2024 16:40:49 +0200 Subject: [PATCH 2/2] t: add sleep to work around rsync failure --- t/podman/script/openSUSE:Factory:ToTest.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/podman/script/openSUSE:Factory:ToTest.sh b/t/podman/script/openSUSE:Factory:ToTest.sh index dcf910cd..e29b6866 100755 --- a/t/podman/script/openSUSE:Factory:ToTest.sh +++ b/t/podman/script/openSUSE:Factory:ToTest.sh @@ -26,11 +26,11 @@ echo 1 > /mockOBS/openSUSE\:Factory\:ToTest/images/local/000product:openSUSE-Add mkdir -p /mockOBS/openSUSE\:Factory\:ToTest/images/local/000product:openSUSE-Addon-NonOss-ftp-ftp-x86_64/openSUSE-Addon-NonOss-FTP-x86_64-Media3 echo 1 > /mockOBS/openSUSE\:Factory\:ToTest/images/local/000product:openSUSE-Addon-NonOss-ftp-ftp-x86_64/openSUSE-Addon-NonOss-FTP-x86_64-Media3/sourcefile -# create just empty files as at this point we are not interested about proper binaries chown -R "$dbuser" /mockOBS ( cd /opt/openqa-trigger-from-obs mkdir -p openSUSE:Factory:ToTest +chown geekotest openSUSE:Factory:ToTest echo geekotest > rsync.secret chmod 600 rsync.secret chown geekotest rsync.secret @@ -43,7 +43,8 @@ python3 script/scriptgen.py openSUSE:Factory:ToTest echo '127.0.0.1 obspublish' >> /etc/hosts systemctl enable --now postgresql -systemctl enable --now rsyncd +systemctl restart rsyncd +sleep 1 # is it a bug that rsyncd needs sleep to work properly? runs_before="$(ls -lda /opt/openqa-trigger-from-obs/openSUSE:Factory:ToTest/base/.run_*/ 2>/dev/null | wc -l)"