1
0
mirror of https://pagure.io/fedora-qa/os-autoinst-distri-fedora.git synced 2025-09-26 16:18:50 +00:00
os-autoinst-distri-fedora/lib/mock.pm
Adam Williamson 4e3bc57a03 Build and test cloud image in updates tests
This makes us create a generic cloud disk image and then run
tests on it, just like we do for Workstation and KDE lives,
everything netinst, Silverblue, and a container image. This is
intended to help avoid anything like
https://bugzilla.redhat.com/show_bug.cgi?id=2390898 happening
again - if we'd had these tests set up and gating enabled, the
update that caused that bug would've been gated.

This requires some changes that affect other things: bind mounting
the whole of /dev in our mock config when using simple isolation,
and forcing START_AFTER_TEST to "" for kiwi_build (this is needed
to override the setting of it in the updates-cloud flavor). bind
mounting is what koji does for 'real' kiwi build jobs so it's fine
(in fact, better); previously the mock config was shared with
livemedia-creator, but we don't use that any more so it's not a
problem.

It's a bit icky when we get to the point of having *multiple*
+START_AFTER_TEST settings, but I can't see another way to get
everything right here and still share the test suite definition
with compose tests.

Moving the definition of KIWI_PROFILE for container tests is not
strictly related, but I noticed it was weird while working on
this and couldn't leave it alone.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
2025-08-28 16:43:07 -07:00

62 lines
3.1 KiB
Perl

package mock;
use strict;
use base 'Exporter';
use Exporter;
use testapi;
use utils;
our @EXPORT = qw/mock_setup/;
sub mock_setup {
my %args = @_;
$args{mountdev} //= 0;
my $version = get_var("VERSION");
my $rawrel = get_var("RAWREL");
my $mockver = $version eq $rawrel ? "rawhide" : $version;
my $arch = get_var("ARCH");
my $tag = get_var("TAG");
my $copr = get_var("COPR");
my $workarounds = get_workarounds;
if (get_var("NUMDISKS") > 2) {
# put /var/lib/mock on the third disk, so we don't run out of
# space on the main disk. The second disk will have already
# been claimed for the update repo.
assert_script_run "echo 'type=83' | sfdisk /dev/vdc";
assert_script_run "mkfs.ext4 /dev/vdc1";
assert_script_run "echo '/dev/vdc1 /var/lib/mock ext4 defaults 1 2' >> /etc/fstab";
assert_script_run "mkdir -p /var/lib/mock";
assert_script_run "mount /var/lib/mock";
}
# base mock config on original
assert_script_run "echo \"include('/etc/mock/fedora-${mockver}-${arch}.cfg')\" > /etc/mock/openqa.cfg";
# make the side and workarounds repos and the serial device available inside the mock root
assert_script_run 'echo "config_opts[\'plugin_conf\'][\'bind_mount_enable\'] = True" >> /etc/mock/openqa.cfg';
assert_script_run 'echo "config_opts[\'plugin_conf\'][\'bind_mount_opts\'][\'dirs\'].append((\'/mnt/update_repo\', \'/mnt/update_repo\'))" >> /etc/mock/openqa.cfg' unless ($tag || $copr);
assert_script_run 'echo "config_opts[\'plugin_conf\'][\'bind_mount_opts\'][\'dirs\'].append((\'/mnt/workarounds_repo\', \'/mnt/workarounds_repo\'))" >> /etc/mock/openqa.cfg' if ($workarounds);
assert_script_run 'echo "config_opts[\'plugin_conf\'][\'bind_mount_opts\'][\'dirs\'].append((\'/dev/\', \'/dev/\'))" >> /etc/mock/openqa.cfg' if ($args{mountdev});
my $repos = 'config_opts[\'dnf.conf\'] += \"\"\"\n';
# add the update, tag or COPR repo to the config
$repos .= '[advisory]\nname=Advisory repo\nbaseurl=file:///mnt/update_repo\nenabled=1\nmetadata_expire=3600\ngpgcheck=0\n' unless ($tag || $copr);
$repos .= '[openqa-testtag]\nname=Tag test repo\nbaseurl=' . get_var("UPDATE_OR_TAG_REPO") . '\nenabled=1\nmetadata_expire=3600\ngpgcheck=0\npriority=1\n' if ($tag || $copr);
# and the workaround repo
$repos .= '\n[workarounds]\nname=Workarounds repo\nbaseurl=file:///mnt/workarounds_repo\nenabled=1\nmetadata_expire=3600\ngpgcheck=0\n' if ($workarounds);
# also the buildroot repo if applicable
my $brrepo = get_var("BUILDROOT_REPO");
if ($brrepo) {
$repos .= '\n[buildroot]\nname=Buildroot repo\nbaseurl=https://kojipkgs.fedoraproject.org/repos/' . $brrepo . '/latest/\$basearch/\nenabled=1\nmetadata_expire=3600\ngpgcheck=0\nskip_if_unavailable=1\n';
}
$repos .= '\"\"\"';
assert_script_run 'printf "' . $repos . '" >> /etc/mock/openqa.cfg';
# replace metalink with mirrorlist so we don't get slow mirrors
repos_mirrorlist "/etc/mock/templates/*.tpl";
# upload the config so we can check it's OK
upload_logs "/etc/mock/openqa.cfg";
}
1;