From: Lennart Poettering Date: Wed, 26 Nov 2025 08:07:28 +0000 (+0100) Subject: ci: add test for OCI downloading X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e31ee582fcd4c5227b78296b78dfdb632e932270;p=thirdparty%2Fsystemd.git ci: add test for OCI downloading --- diff --git a/test/units/TEST-13-NSPAWN.pull-oci.sh b/test/units/TEST-13-NSPAWN.pull-oci.sh new file mode 100755 index 00000000000..e673b711f0f --- /dev/null +++ b/test/units/TEST-13-NSPAWN.pull-oci.sh @@ -0,0 +1,145 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +# shellcheck disable=SC2016 +set -eux +set -o pipefail + +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh + +if ! can_do_rootless_nspawn; then + echo "Skipping unpriv nspawn test" + exit 0 +fi + +# We need FSCONFIG_SET_FD support in overlayfs for .mstack to work. Let's skip +# this test on old kernels, that didn't have that yet. Ideally we'd check for +# the feature itself here, but I couldn't figure out a nice way to detect +# support for this from shell, hence let's do a version check instead. +if systemd-analyze condition 'ConditionVersion= < 6.13' ; then + echo "Kernel too old for FSCONFIG_SET_FD support on overlayfs, skipping pull-oci test". + exit 0 +fi + +export SYSTEMD_LOG_LEVEL=debug +export SYSTEMD_LOG_TARGET=journal + +at_exit() { + rm -rf /var/tmp/pull-oci-test + rm -rf /home/testuser/.local/state/machines/ocibasic + rm -rf /home/testuser/.local/state/machines/ocilayer +} + +trap at_exit EXIT + +# Install a PK rule that allows 'testuser' user to register a machine even +# though they are not on an fg console, just for testing +mkdir -p /etc/polkit-1/rules.d +cat >/etc/polkit-1/rules.d/registermachinetest.rules <<'EOF' +polkit.addRule(function(action, subject) { + if (action.id == "org.freedesktop.machine1.register-machine" && + subject.user == "testuser") { + return polkit.Result.YES; + } +}); +EOF + +run0 -u testuser mkdir -p .local/state/machines + +create_dummy_container /home/testuser/.local/state/machines/ocibasic +cat >/home/testuser/.local/state/machines/ocibasic/sbin/init <home/testuser/.local/state/machines/ocilayer/etc/waldo </var/tmp/pull-oci-test/ocibasic.tar.gz +run0 --pipe -u testuser importctl -m --user export-tar --format=gzip ocilayer - >/var/tmp/pull-oci-test/ocilayer.tar.gz + +OCIBASIC_SHA256="$(sha256sum /var/tmp/pull-oci-test/ocibasic.tar.gz | cut -d' ' -f1)" +OCIBASIC_SIZE="$(stat -c %s /var/tmp/pull-oci-test/ocibasic.tar.gz)" +OCILAYER_SHA256="$(sha256sum /var/tmp/pull-oci-test/ocilayer.tar.gz | cut -d' ' -f1)" +OCILAYER_SIZE="$(stat -c %s /var/tmp/pull-oci-test/ocilayer.tar.gz)" + +# Let's now put together a simple, fake, static OCI registry that sits on +# file:// rather than https://, so that we don't have to spawn an HTTP +# server. After all we don't want to test the server side code, but only the +# client side code, and libcurl nicely abstracts https:// or ftp:// from us. + +mkdir -p /var/tmp/pull-oci-test/v2/ocicombo/manifests +cat >/var/tmp/pull-oci-test/v2/ocicombo/manifests/latest < /usr/lib/systemd/oci-registry/registry.localfile.oci-registry <