Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37423590
en ru br
ALT Linux repos
S:1.57-alt1

Group :: Development/Other
RPM: rpm-build-vm

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

# SPDX-License-Identifier: GPL-2.0-only
# Copyright (C) 2019 Vitaly Chikunov <vt at altlinux.org>
%define _unpackaged_files_terminate_build 1
%define _stripped_files_terminate_build 1

Name: rpm-build-vm
Version: 1.56
Release: alt1

Summary: RPM helper to run tests in virtualised environment
License: GPL-2.0-only
Group: Development/Other
Url: https://www.altlinux.org/Hasher/vm-run
Vcs: https://github.com/vt-alt/vm-run

Source: %name-%version.tar

%define supported_arches %ix86 x86_64 ppc64le aarch64 armh

%ifarch %supported_arches
BuildRequires: glibc-devel-static
BuildRequires: libblkid-devel-static
# For %%check. This does not verify the package but verifies
# that girar on supported_arches have writable /dev/kvm
# This should run even if check is disabled.
BuildRequires: /dev/kvm
# shellchek is used in %%build as pre-install syntax check.
%ifarch %ix86 x86_64
# There is no shellcheck on other arches in p9. 'make shellcheck' below can
# handle absence of shellcheck binary using only 'bash -n'.
BuildRequires: shellcheck
%endif

# Try to load un-def kernel this way to avoid "forbidden dependencies"

# from sisyphus_check.
Requires(pre): kernel >= 5.7
%endif

Requires(pre): %name-run = %EVR

%ifarch %supported_arches
%description
RPM helper to run QEMU inside hasher. This is mainly intended
for %%check section to test software under better emulated root
than fakeroot.

This is similar to multiple vm scripts, virtme, vido, and eudyptula-boot.
%else
%description
This package is a stub instead of RPM helper to run QEMU inside hasher
on supported architectures (this one (%_arch) is unsupported).
%endif

%package run
Summary: vm-run virtualized runner
Group: Development/Other

# Other arches will get a stub which will always return success

%ifarch %supported_arches
Requires: mount

# /proc is required for qemu 9p to work, otherwise you'll get

# confusing ENOENT when creating a file. This is because
# `qemu/hw/9pfs/9p-local.c:fchmodat_nofollow' is doing chmod
# over `/proc/self/fd/%%d'.
Requires: /proc
Requires: /dev/kvm

%ifarch %ix86 x86_64
Requires: qemu-system-x86-core
%endif
%ifarch ppc64le
Requires: qemu-system-ppc-core
%endif
%ifarch aarch64
Requires: qemu-system-aarch64-core
%endif
%ifarch armh
# No KVM support in the kernel for this arch.
Requires: qemu-system-arm-core
# AArch64-native qemu-system-aarch64 binary to use KVM.
Requires: qemu-system-aarch64-core-bundle
%endif

%endif

%ifarch %supported_arches
%description run
RPM helper to run QEMU inside hasher. This is mainly intended
for %%check section to test software under better emulated root
than fakeroot.

This is similar to multiple vm scripts, virtme, vido, and eudyptula-boot.

This package is vm-run scripts only (without requirement on the kernel).
%else
%description run
This package is a stub instead of RPM helper to run QEMU inside hasher
on supported architectures (this one (%_arch) is unsupported).
%endif

%package createimage
Summary: Filetrigger to create ext4 image for vm-run
Group: Development/Other
BuildArch: noarch
Requires: %name = %EVR

%description createimage
This is optional package containing a filetrigger to create an ext4 image
at "/tmp/vm-ext4.img" out of your hasher root to run vm-run with it as rootfs.

%package checkinstall
Summary: Checkinstall for vm-run
Group: Development/Other
BuildArch: noarch
Requires(pre): %name-createimage = %EVR
Requires(pre): procps
Requires(pre): time

%description checkinstall
Run checkinstall tests for vm-run.

%prep
%setup

%ifarch %supported_arches
%build
%{?optflags_lto:%global optflags_lto %optflags_lto -ffat-lto-objects}
CFLAGS="%optflags" make

# This is pre-install syntax check for bash scripts. This does not

# run any functional tests.
make shellcheck
%else
# Still useful to verify stub script even in absence of shellcheck.
bash -n vm-run
%endif

%install
%ifnarch %supported_arches
install -D -p -m 0755 vm-run-stub %buildroot%_bindir/vm-run
%else
install -D -p -m 0755 vm-run      %buildroot%_bindir/vm-run
install -D -p -m 0755 vm-create-image %buildroot%_bindir/vm-create-image
install -D -p -m 0755 vm-initrd   %buildroot%_bindir/vm-initrd
install -D -p -m 0755 vm-init     %buildroot%_libexecdir/vm-run/vm-init
install -D -p -m 0755 initrd-init %buildroot%_libexecdir/vm-run/initrd-init
install -D -p -m 0755 fakesudo    %buildroot%_libexecdir/vm-run/vm-fakesudo
install -D -p -m 0755 filetrigger %buildroot%_rpmlibdir/vm-run.filetrigger
install -D -p -m 0755 createimage %buildroot%_rpmlibdir/z-vm-createimage.filetrigger
install -Dp bash_completion %buildroot%_sysconfdir/bashrc.d/vm_completion.sh
install -D -p -m 0755 vm-resize   %buildroot%_bindir/vm-resize
%endif
install -D -p -m 0755 kvm-ok      %buildroot%_bindir/kvm-ok

%pre run
# Only allow to install inside of hasher.
[ -d /.host -a -d /.in -a -d /.out ] || {
       echo >&2 'rpm-build-vm-run is not allowed outside hasher environments'
       exit 1
}

%files

%files checkinstall

%files createimage
%ifarch %supported_arches
%_rpmlibdir/z-vm-createimage.filetrigger
%endif

%files run
%_bindir/vm-run
%_bindir/kvm-ok

%ifarch %supported_arches
%_bindir/vm-initrd
%_bindir/vm-resize
%_bindir/vm-create-image
%_libexecdir/vm-run
%_rpmlibdir/vm-run.filetrigger
%_sysconfdir/bashrc.d/vm*.sh

%post run
# u&mount should to be readable to use inside vm
control mount unprivileged

# Useful for enable audit for some kernel-modules tests

[ ! -x /sbin/auditctl ] || chmod a+rx /sbin/auditctl

# For --overlay=

chmod a+twx /mnt

# Allow user creation (for openssh)

chmod a+r /etc/login.defs

# Call filetrigger for the past kernels.

find /boot | %_rpmlibdir/vm-run.filetrigger

%pre checkinstall
PS4=$'\n+ '
set -ex
# qemu in tcg mode can hang un-def-5.10 kernel on ppc64 if smp>1 on "smp:
# Bringing up secondary CPUs" message.
ls -l /dev/kvm
set | grep ^LD_

# Simulate filetrigger run

find /boot > /tmp/filelist
%_rpmlibdir/posttrans-filetriggers /tmp/filelist
rm /tmp/filelist
# Remove trigger so it does not re-create '/tmp/vm-ext4.img'.
> %_rpmlibdir/z-vm-createimage.filetrigger

kvm-ok
timeout 300 vm-run --verbose uname -a
timeout 300 vm-run --mem=max free -g
timeout 300 vm-run --mem=256 --cpu=max lscpu
df -h /tmp
timeout 300 vm-run --tmp=max df -h /tmp
rm /tmp/vm-tmpfs.qcow2
timeout 300 vm-run --verbose --overlay=ext4 uname -a
rmdir /mnt/0
rm /usr/src/ext4.0.img
! timeout --preserve-status 300 vm-run --verbose exit 1
timeout 300 vm-run --rootfs --verbose df
rm /tmp/vm-ext4.img
timeout 300 vm-run --hvc --no-quiet 'dmesg -r | grep Unknown'
timeout 300 vm-run --tcg --mem='' --cpu=1 cat /proc/cpuinfo
# Clean up without '-f' ensures these files existed.
rm /tmp/initramfs-*un-def-alt*.img
# SCRIPT and exit code files form each vm-run invocation. Each SCRIPT file
# should correspond to '.ret' file.
find /tmp/vm.?????????? -maxdepth 0 | xargs -t -i -n1 rm {} {}.ret

%check
# Verify availability of KVM in girar & beehiver.
ls -l /dev/kvm && test -w /dev/kvm
%endif

%changelog

Full changelog you can see here

 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin