2
0
mirror of https://github.com/xcat2/xcat-dep.git synced 2026-10-18 17:50:36 +00:00

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>
This commit is contained in:
Daniel Hilst
2026-10-07 13:48:09 -03:00
parent 2a1762b22c
commit 329f7dc5f3
2 changed files with 48 additions and 0 deletions
@@ -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
+36
View File
@@ -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();