From 16f762c2ed3713b02fdf1bafe481ffebac792194 Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Thu, 19 Nov 2020 00:05:36 +0100 Subject: [PATCH] test: move to koji-osbuild-tests package This is similar to how other osbuild packages are testing: everything that's needed for testing is included in the tests package or a dependency of it. The test runner then runs every executable in /usr/libexec/tests/. This gives a simple test API to projects depending on this package (notably osbuild-composer). The local development workflow described in HACKING.md is meant to continue to work. To ensure this, all relevant scripts gained a TEST_DATA variable, which defaults to `./test`, but is set from $1 to the installed path from integration.sh. --- koji-osbuild.spec.in | 70 ++++++++++++++++++++++++ schutzbot/Jenkinsfile | 2 +- schutzbot/deploy.sh | 4 +- test/build-container.sh | 6 +- test/container/builder/Dockerfile.fedora | 7 +-- test/container/builder/Dockerfile.rhel | 11 ++-- test/container/builder/run-kojid.sh | 10 ++-- test/container/hub/Dockerfile.fedora | 11 ++-- test/container/hub/Dockerfile.rhel | 15 +++-- test/container/hub/run-hub.sh | 10 ++-- test/copy-creds.sh | 3 +- test/integration.sh | 37 +++++-------- test/make-certs.sh | 3 +- test/run-builder.sh | 7 ++- 14 files changed, 132 insertions(+), 64 deletions(-) diff --git a/koji-osbuild.spec.in b/koji-osbuild.spec.in index 6c890e7..f0b5730 100644 --- a/koji-osbuild.spec.in +++ b/koji-osbuild.spec.in @@ -64,6 +64,50 @@ install -d %{buildroot}%{python3_sitelib}/koji_cli_plugins install -p -m 0644 plugins/cli/osbuild.py %{buildroot}%{python3_sitelib}/koji_cli_plugins/osbuild.py %py_byte_compile %{__python3} %{buildroot}%{python3_sitelib}/koji_cli_plugins/osbuild.py +# Tests +install -m 0755 -vd %{buildroot}/%{_libexecdir}/tests/%{name} +install -m 0755 -vp test/integration.sh %{buildroot}/%{_libexecdir}/tests/%{name}/ + +install -m 0755 -vd %{buildroot}/%{_libexecdir}/%{name}-tests +install -m 0755 -vp test/make-certs.sh %{buildroot}/%{_libexecdir}/%{name}-tests/ +install -m 0755 -vp test/build-container.sh %{buildroot}/%{_libexecdir}/%{name}-tests/ +install -m 0755 -vp test/run-koji-container.sh %{buildroot}/%{_libexecdir}/%{name}-tests/ +install -m 0755 -vp test/copy-creds.sh %{buildroot}/%{_libexecdir}/%{name}-tests/ +install -m 0755 -vp test/run-builder.sh %{buildroot}/%{_libexecdir}/%{name}-tests/ +install -m 0755 -vp test/make-tags.sh %{buildroot}/%{_libexecdir}/%{name}-tests/ + +install -m 0755 -vd %{buildroot}/%{_libexecdir}/%{name}-tests/integration +install -m 0755 -vp test/integration/* %{buildroot}/%{_libexecdir}/%{name}-tests/integration/ + +install -m 0755 -vd %{buildroot}/%{_datadir}/%{name}-tests + +install -m 0755 -vd %{buildroot}/%{_datadir}/%{name}-tests/data +install -m 0755 -vp test/data/* %{buildroot}/%{_datadir}/%{name}-tests/data/ + +install -m 0755 -vd %{buildroot}/%{_datadir}/%{name}-tests/container +install -m 0755 -vp test/container/brew.repo %{buildroot}/%{_datadir}/%{name}-tests/container/ +install -m 0755 -vp test/container/rhel.repo %{buildroot}/%{_datadir}/%{name}-tests/container/ + +install -m 0755 -vd %{buildroot}/%{_datadir}/%{name}-tests/container/builder +install -m 0755 -vp test/container/builder/Dockerfile.fedora %{buildroot}/%{_datadir}/%{name}-tests/container/builder/ +install -m 0755 -vp test/container/builder/Dockerfile.rhel %{buildroot}/%{_datadir}/%{name}-tests/container/builder/ +install -m 0755 -vp test/container/builder/kojid.conf %{buildroot}/%{_datadir}/%{name}-tests/container/builder/ +install -m 0755 -vp test/container/builder/osbuild-koji.conf %{buildroot}/%{_datadir}/%{name}-tests/container/builder/ +install -m 0755 -vp test/container/builder/osbuild.krb5.conf %{buildroot}/%{_datadir}/%{name}-tests/container/builder/ +install -m 0755 -vp test/container/builder/run-kojid.sh %{buildroot}/%{_datadir}/%{name}-tests/container/builder/ + +install -m 0755 -vd %{buildroot}/%{_datadir}/%{name}-tests/container/hub +install -m 0755 -vp test/container/hub/Dockerfile.fedora %{buildroot}/%{_datadir}/%{name}-tests/container/hub/ +install -m 0755 -vp test/container/hub/Dockerfile.rhel %{buildroot}/%{_datadir}/%{name}-tests/container/hub/ +install -m 0755 -vp test/container/hub/hub.conf %{buildroot}/%{_datadir}/%{name}-tests/container/hub/ +install -m 0755 -vp test/container/hub/kojiweb.conf %{buildroot}/%{_datadir}/%{name}-tests/container/hub/ +install -m 0755 -vp test/container/hub/run-hub.sh %{buildroot}/%{_datadir}/%{name}-tests/container/hub/ +install -m 0755 -vp test/container/hub/ssl.conf %{buildroot}/%{_datadir}/%{name}-tests/container/hub/ +install -m 0755 -vp test/container/hub/web.conf %{buildroot}/%{_datadir}/%{name}-tests/container/hub/ + +install -m 0755 -vd %{buildroot}/%{_datadir}/%{name}-tests/container/hub/plugin +install -m 0755 -vp test/container/hub/plugin/osbuild.py %{buildroot}/%{_datadir}/%{name}-tests/container/hub/ + %files %license LICENSE %doc README.md @@ -80,6 +124,32 @@ install -p -m 0644 plugins/cli/osbuild.py %{buildroot}%{python3_sitelib}/koji_cl %{python3_sitelib}/koji_cli_plugins/osbuild.py %{python3_sitelib}/koji_cli_plugins/__pycache__/osbuild.* +%package tests +Summary: Integration tests for koji-osbuild +Requires: %{name} = %{version}-%{release} +Requires: %{name}-cli +Requires: container-selinux +Requires: dnsmasq +Requires: jq +Requires: koji +Requires: krb5-workstation +Requires: openssl +Requires: osbuild-composer >= 22 +Requires: podman + +# See comment in test/integration.sh +%if 0%{?fedora} +Requires: podman-plugins +%endif + +%description tests +Integration tests for koji-osbuild. To be run on a dedicated system. + +%files tests +%{_libexecdir}/tests/%{name} +%{_libexecdir}/%{name}-tests +%{_datadir}/%{name}-tests + %changelog * @longdate@ osbuild - @version@-@reltag@ diff --git a/schutzbot/Jenkinsfile b/schutzbot/Jenkinsfile index 5d5890e..3e897f1 100644 --- a/schutzbot/Jenkinsfile +++ b/schutzbot/Jenkinsfile @@ -158,7 +158,7 @@ void run_tests(test_type) { if (test_type == 'integration') { sh ( label: "Integration tests", - script: "test/integration.sh" + script: "/usr/libexec/tests/koji-osbuild/integration.sh" ) } diff --git a/schutzbot/deploy.sh b/schutzbot/deploy.sh index e88cce4..6d228e0 100755 --- a/schutzbot/deploy.sh +++ b/schutzbot/deploy.sh @@ -84,8 +84,8 @@ gpgcheck=0 priority=10 EOF -# Install the Image Builder packages and the koji cli plugin. -retry sudo dnf -y install osbuild-composer koji-osbuild-cli +# Installing koji-osbuild-tests package +retry sudo dnf -y install koji-osbuild-tests # Start services. sudo systemctl enable --now osbuild-composer.socket diff --git a/test/build-container.sh b/test/build-container.sh index a7e681f..7ee4c05 100755 --- a/test/build-container.sh +++ b/test/build-container.sh @@ -1,6 +1,8 @@ #!/bin/bash set -euo pipefail +TEST_PATH=${1:-test} + # this script must be run as root if [ $UID != 0 ]; then echo This script must be run as root. @@ -11,8 +13,8 @@ source /etc/os-release podman build \ -t koji.hub \ - -f test/container/hub/Dockerfile.${ID} . + -f ${TEST_PATH}/container/hub/Dockerfile.${ID} $TEST_PATH podman build -t \ koji.builder \ - -f test/container/builder/Dockerfile.${ID} . + -f ${TEST_PATH}/container/builder/Dockerfile.${ID} $TEST_PATH diff --git a/test/container/builder/Dockerfile.fedora b/test/container/builder/Dockerfile.fedora index 6925a17..961d0fa 100644 --- a/test/container/builder/Dockerfile.fedora +++ b/test/container/builder/Dockerfile.fedora @@ -13,9 +13,8 @@ RUN dnf -y upgrade \ python3-requests \ && dnf clean all -COPY test/container/builder/kojid.conf /etc/kojid/kojid.conf -COPY plugins/builder/osbuild.py /usr/lib/koji-builder-plugins/ -COPY test/container/builder/run-kojid.sh /app/run-kojid.sh -COPY test/container/builder/osbuild.krb5.conf /etc/krb5.conf.d/ +COPY container/builder/kojid.conf /etc/kojid/kojid.conf +COPY container/builder/run-kojid.sh /app/run-kojid.sh +COPY container/builder/osbuild.krb5.conf /etc/krb5.conf.d/ ENTRYPOINT /app/run-kojid.sh diff --git a/test/container/builder/Dockerfile.rhel b/test/container/builder/Dockerfile.rhel index e0ce8e8..7eec64d 100644 --- a/test/container/builder/Dockerfile.rhel +++ b/test/container/builder/Dockerfile.rhel @@ -1,7 +1,7 @@ FROM registry.access.redhat.com/ubi8/ubi:latest -COPY test/container/rhel.repo /etc/yum.repos.d/ -COPY test/container/brew.repo /etc/yum.repos.d/ +COPY container/rhel.repo /etc/yum.repos.d/ +COPY container/brew.repo /etc/yum.repos.d/ RUN dnf -y upgrade \ && dnf -y \ @@ -14,9 +14,8 @@ RUN dnf -y upgrade \ python3-requests \ && dnf clean all -COPY test/container/builder/kojid.conf /etc/kojid/kojid.conf -COPY plugins/builder/osbuild.py /usr/lib/koji-builder-plugins/ -COPY test/container/builder/run-kojid.sh /app/run-kojid.sh -COPY test/container/builder/osbuild.krb5.conf /etc/krb5.conf.d/ +COPY container/builder/kojid.conf /etc/kojid/kojid.conf +COPY container/builder/run-kojid.sh /app/run-kojid.sh +COPY container/builder/osbuild.krb5.conf /etc/krb5.conf.d/ ENTRYPOINT /app/run-kojid.sh diff --git a/test/container/builder/run-kojid.sh b/test/container/builder/run-kojid.sh index a2acf05..330bd32 100755 --- a/test/container/builder/run-kojid.sh +++ b/test/container/builder/run-kojid.sh @@ -2,10 +2,12 @@ set -ux if ls /share/rpms/*.rpm 1> /dev/null 2>&1; then - echo "Using RPMs" - rm /usr/lib/koji-builder-plugins/osbuild.py - rpm -i /share/rpms/koji-osbuild-?-0.*.rpm \ - /share/rpms/koji-osbuild-builder-*.rpm + echo "Using RPMs" + rpm -i /share/rpms/koji-osbuild-?-0.*.rpm \ + /share/rpms/koji-osbuild-builder-*.rpm +else + echo "Using local plugin" + cp /share/plugins/builder/osbuild.py /usr/lib/koji-builder-plugins/ fi KOJI="koji --server=http://org.osbuild.koji.koji/kojihub --user=kojiadmin --password=kojipass --authtype=password" diff --git a/test/container/hub/Dockerfile.fedora b/test/container/hub/Dockerfile.fedora index c992b28..9a810f2 100644 --- a/test/container/hub/Dockerfile.fedora +++ b/test/container/hub/Dockerfile.fedora @@ -9,12 +9,11 @@ RUN dnf -y upgrade \ python3-jsonschema \ && dnf clean all -COPY test/container/hub/hub.conf /etc/koji-hub/hub.conf -COPY test/container/hub/ssl.conf /etc/httpd/conf.d/ssl.conf -COPY plugins/hub/osbuild.py /usr/lib/koji-hub-plugins/ -COPY test/container/hub/run-hub.sh /app/run-hub.sh +COPY container/hub/hub.conf /etc/koji-hub/hub.conf +COPY container/hub/ssl.conf /etc/httpd/conf.d/ssl.conf +COPY container/hub/run-hub.sh /app/run-hub.sh -COPY test/container/hub/web.conf /etc/kojiweb/web.conf -COPY test/container/hub/kojiweb.conf /etc/httpd/conf.d/kojiweb.conf +COPY container/hub/web.conf /etc/kojiweb/web.conf +COPY container/hub/kojiweb.conf /etc/httpd/conf.d/kojiweb.conf ENTRYPOINT /app/run-hub.sh diff --git a/test/container/hub/Dockerfile.rhel b/test/container/hub/Dockerfile.rhel index f558816..86fb509 100644 --- a/test/container/hub/Dockerfile.rhel +++ b/test/container/hub/Dockerfile.rhel @@ -1,7 +1,7 @@ FROM registry.access.redhat.com/ubi8/ubi:latest -COPY test/container/rhel.repo /etc/yum.repos.d/ -COPY test/container/brew.repo /etc/yum.repos.d/ +COPY container/rhel.repo /etc/yum.repos.d/ +COPY container/brew.repo /etc/yum.repos.d/ # koji db schema is in docs, remove nodocs from from dnf config RUN sed -i '/^tsflags=nodocs$/d' /etc/dnf/dnf.conf @@ -18,12 +18,11 @@ RUN dnf -y upgrade \ python3-jsonschema \ && dnf clean all -COPY test/container/hub/hub.conf /etc/koji-hub/hub.conf -COPY test/container/hub/ssl.conf /etc/httpd/conf.d/ssl.conf -COPY plugins/hub/osbuild.py /usr/lib/koji-hub-plugins/ -COPY test/container/hub/run-hub.sh /app/run-hub.sh +COPY container/hub/hub.conf /etc/koji-hub/hub.conf +COPY container/hub/ssl.conf /etc/httpd/conf.d/ssl.conf +COPY container/hub/run-hub.sh /app/run-hub.sh -COPY test/container/hub/web.conf /etc/kojiweb/web.conf -COPY test/container/hub/kojiweb.conf /etc/httpd/conf.d/kojiweb.conf +COPY container/hub/web.conf /etc/kojiweb/web.conf +COPY container/hub/kojiweb.conf /etc/httpd/conf.d/kojiweb.conf ENTRYPOINT /app/run-hub.sh diff --git a/test/container/hub/run-hub.sh b/test/container/hub/run-hub.sh index 67a3df0..d521f98 100755 --- a/test/container/hub/run-hub.sh +++ b/test/container/hub/run-hub.sh @@ -2,10 +2,12 @@ set -eux if ls /share/rpms/*.rpm 1> /dev/null 2>&1; then - echo "Using RPMs" - rm /usr/lib/koji-hub-plugins/osbuild.py - rpm -i /share/rpms/koji-osbuild-?-0.*.rpm \ - /share/rpms/koji-osbuild-hub-*.rpm + echo "Using RPMs" + rpm -i /share/rpms/koji-osbuild-?-0.*.rpm \ + /share/rpms/koji-osbuild-hub-*.rpm +else + echo "Using local plugin" + cp /share/plugins/hub/osbuild.py /usr/lib/koji-hub-plugins/ fi # Set DB credentials diff --git a/test/copy-creds.sh b/test/copy-creds.sh index 2401e10..c6fe85b 100755 --- a/test/copy-creds.sh +++ b/test/copy-creds.sh @@ -7,7 +7,8 @@ if [ $UID != 0 ]; then exit 1 fi -TEST_DATA=${TEST_DATA:-test/data} +TEST_PATH=${1:-test} +TEST_DATA=${TEST_PATH}/data SHARE_DIR=${SHARE_DIR:-/tmp/osbuild-composer-koji-test} mkdir -p "${SHARE_DIR}" diff --git a/test/integration.sh b/test/integration.sh index 6684beb..a99a8e8 100755 --- a/test/integration.sh +++ b/test/integration.sh @@ -15,18 +15,10 @@ if [[ $ID == rhel ]] && ! rpm -q epel-release; then sudo rpm -Uvh /tmp/epel.rpm fi -greenprint "Installing required packages" -sudo dnf -y install \ - container-selinux \ - dnsmasq \ - jq \ - krb5-workstation \ - koji \ - koji-osbuild-cli \ - podman - # HACK: podman-plugins was only recently added to RHEL. Fetch it from the -# internal RHEL 8.3.1 repository until that is released. +# internal RHEL 8.3.1 repository until that is released. On Fedora, +# podman-plugins is installed in the koji-osbuild-tests package. Please adjust +# the spec file to do the same on RHEL before removing this block. greenprint "Install the podman dnsname plugin" if [[ $ID == rhel ]]; then sudo tee /etc/yum.repos.d/rhel-8-3-1.repo << EOF @@ -38,8 +30,6 @@ gpgcheck = 1 EOF sudo dnf -y install '--disablerepo=*' --enablerepo=rhel-8-3-1 podman-plugins -else - sudo dnf -y install podman-plugins fi greenprint "Fetching RPMs" @@ -51,37 +41,40 @@ sudo dnf -y \ "koji-osbuild*" greenprint "Creating composer SSL certificates" -sudo test/make-certs.sh +sudo /usr/libexec/koji-osbuild-tests/make-certs.sh /usr/share/koji-osbuild-tests + +greenprint "Starting osbuild-composer's socket" +sudo systemctl enable --now osbuild-composer-api.socket greenprint "Building containers" -sudo test/build-container.sh +sudo /usr/libexec/koji-osbuild-tests/build-container.sh /usr/share/koji-osbuild-tests greenprint "Starting containers" -sudo test/run-koji-container.sh start +sudo /usr/libexec/koji-osbuild-tests/run-koji-container.sh start greenprint "Print logs" sudo podman logs org.osbuild.koji.koji greenprint "Copying credentials and certificates" -sudo test/copy-creds.sh +sudo /usr/libexec/koji-osbuild-tests/copy-creds.sh /usr/share/koji-osbuild-tests greenprint "Testing Koji hub API access" koji --server=http://localhost:8080/kojihub --user=osbuild --password=osbuildpass --authtype=password hello greenprint "Starting koji builder" -sudo test/run-builder.sh start +sudo /usr/libexec/koji-osbuild-tests/run-builder.sh start /usr/share/koji-osbuild-tests greenprint "Creating Koji tag infrastructure" -test/make-tags.sh +/usr/libexec/koji-osbuild-tests/make-tags.sh greenprint "Running integration tests" -python3 -m unittest discover -v test/integration/ +python3 -m unittest discover -v /usr/libexec/koji-osbuild-tests/integration/ greenprint "Stopping koji builder" -sudo test/run-builder.sh stop +sudo /usr/libexec/koji-osbuild-tests/run-builder.sh stop /usr/share/koji-osbuild-tests greenprint "Stopping containers" -sudo test/run-koji-container.sh stop +sudo /usr/libexec/koji-osbuild-tests/run-koji-container.sh stop greenprint "Removing generated CA cert" sudo rm /etc/pki/ca-trust/source/anchors/osbuild-ca-crt.pem diff --git a/test/make-certs.sh b/test/make-certs.sh index fc52186..8e9104b 100755 --- a/test/make-certs.sh +++ b/test/make-certs.sh @@ -7,7 +7,8 @@ if [ $UID != 0 ]; then exit 1 fi -TEST_DATA=${TEST_DATA:-test/data} +TEST_PATH=${1:-test} +TEST_DATA=${TEST_PATH}/data CA_DIR="/etc/osbuild-composer" echo "Generating certificates" diff --git a/test/run-builder.sh b/test/run-builder.sh index 4cedb11..dfb3e31 100755 --- a/test/run-builder.sh +++ b/test/run-builder.sh @@ -1,6 +1,7 @@ #!/usr/bin/bash set -euo pipefail +TEST_PATH=${2:-test} SHARE_DIR=${SHARE_DIR:-/tmp/osbuild-composer-koji-test} DATA_DIR=${DATA_DIR:-/var/tmp/osbuild-koji-data} @@ -28,7 +29,7 @@ builder_start() { --name org.osbuild.koji.builder --network org.osbuild.koji \ -v "${SHARE_DIR}:/share:z" \ -v "${DATA_DIR}:/mnt:z" \ - -v "${PWD}/test/container/builder/osbuild-koji.conf:/etc/koji-osbuild/builder.conf:z" \ + -v "${TEST_PATH}/container/builder/osbuild-koji.conf:/etc/koji-osbuild/builder.conf" \ --hostname org.osbuild.koji.kojid \ --add-host=composer:${GATEWAY_IP} \ koji.builder @@ -40,9 +41,9 @@ builder_stop() { } # check arguments -if [[ $# -ne 1 || ( "$1" != "start" && "$1" != "stop" && "$1" != "fg") ]]; then +if [[ $# -lt 1 || ( "$1" != "start" && "$1" != "stop" && "$1" != "fg") ]]; then cat <