From 329f7dc5f35487812968f4e6f40e13ce80b16174 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Wed, 7 Oct 2026 13:48:09 -0300 Subject: [PATCH] test(xcat-dep): mock_chroot_uid ignores a chrootuid set after an include mock_chroot_uid reads the configuration files itself and processes each include() after the file that names it. A configuration that includes a file with chrootuid 1000 and then sets chrootuid 1001 returns 1000, but mock builds as 1001. mockbuild-perl-packages.pl then gives the result directories to the wrong uid, and mock cannot write its logs in them. native/mock-chroot-uid.t compares mock_chroot_uid with that case, with a wrapper that only includes, and with a configuration that sets no chrootuid. Ubuntu ships no mock, so the workflow runs the test in a Fedora container. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .github/workflows/genesis-openembedded.yml | 12 ++++++++ native/mock-chroot-uid.t | 36 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 native/mock-chroot-uid.t diff --git a/.github/workflows/genesis-openembedded.yml b/.github/workflows/genesis-openembedded.yml index bde8ffa..8a4885b 100644 --- a/.github/workflows/genesis-openembedded.yml +++ b/.github/workflows/genesis-openembedded.yml @@ -97,3 +97,15 @@ jobs: echo 'a native test file was skipped' >&2 exit 1 fi + + # Ubuntu ships no mock, so the test of mock's configuration loader runs on Fedora. + - name: Run mock configuration loader test + run: | + set -o pipefail + docker run --rm -v "$PWD:/src:ro" -w /src fedora:42 bash -ec ' + dnf -y -q install mock perl perl-File-Slurper >/dev/null + prove -v native/mock-chroot-uid.t' 2>&1 | tee mock.tap + if grep -E '^1\.\.0 # SKIP|^native/[^ ]+\.t \.+ skipped' mock.tap; then + echo 'the mock configuration loader test was skipped' >&2 + exit 1 + fi diff --git a/native/mock-chroot-uid.t b/native/mock-chroot-uid.t new file mode 100644 index 0000000..510c3c2 --- /dev/null +++ b/native/mock-chroot-uid.t @@ -0,0 +1,36 @@ +#!/usr/bin/env perl +# mock_chroot_uid must give the uid mock itself builds as, so it runs mock's own loader. +use strict; +use warnings; + +use File::Slurper qw(write_text); +use File::Temp qw(tempdir); +use FindBin qw($RealBin); +use Test::More; + +use lib "$RealBin/.."; +use MockBuildUtils qw(mock_chroot_uid); + +plan skip_all => 'native Mock Python library required' + if system('python3 -c "import mockbuild.config" >/dev/null 2>&1') != 0; + +my $tmp = tempdir(CLEANUP => 1); +write_text("$tmp/base.cfg", <<'CFG'); +config_opts['root'] = 'xcat-chrootuid-base' +config_opts['chrootuid'] = 1000 +CFG +write_text("$tmp/override.cfg", <<"CFG"); +include('$tmp/base.cfg') +config_opts['chrootuid'] = 1001 +CFG +write_text("$tmp/wrapper.cfg", <<"CFG"); +include('$tmp/base.cfg') +config_opts['environment']['SOURCE_DATE_EPOCH'] = '1757000000' +CFG +write_text("$tmp/plain.cfg", "config_opts['root'] = 'xcat-chrootuid-plain'\n"); + +is(mock_chroot_uid("$tmp/override.cfg"), 1001, 'a chrootuid set after an include overrides the include'); +is(mock_chroot_uid("$tmp/wrapper.cfg"), 1000, 'a wrapper keeps the chrootuid of the configuration it includes'); +is(mock_chroot_uid("$tmp/plain.cfg"), $<, 'a configuration with no chrootuid keeps the uid that runs mock'); + +done_testing();