Source: libguestfs Version: 1:1.40.2-2+b10 Severity: wishlist Tags: patch Hi,
it would be great if src:libguestfs would include an autopkgtest, so that we regularly verify that basic functionality still works and as yet another example of how to use libguestfs from a script. I attached a patch which first creates a tarball containing a Debian unstable chroot and then uses guestfish to create a disk image with extlinux. Lastly, qemu is used to boot the image and we verify that everything works by connecting to it via ssh. If you want to verify that all of this works you can run: $ sudo debian/tests/extlinux In principal, all the tools the script uses can also work without superuser privileges. But due to limitations on ci.debian.net and salsa-ci, we cannot use linux user namespaces and need root instead. If you want to run the script on your local machine without root permissions, then replace --mode=root with --mode=unshare in the autopkgtest and then run the script without sudo in front. It will work just as well. I also added a debian/salsa-ci.yml but that one is not useful yet, because libguestfs seems too large for salsa-ci. See: https://salsa.debian.org/salsa/support/issues/175 Thanks! cheers, josch
>From a650d5c1f9bc260996e25079d50114cb7dbddc5a Mon Sep 17 00:00:00 2001 From: Johannes 'josch' Schauer <jo...@debian.org> Date: Thu, 14 Nov 2019 11:21:03 +0100 Subject: [PATCH] add autopkgtest --- debian/salsa-ci.yml | 14 ++++++ debian/tests/control | 2 + debian/tests/extlinux | 99 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 debian/salsa-ci.yml create mode 100644 debian/tests/control create mode 100644 debian/tests/extlinux diff --git a/debian/salsa-ci.yml b/debian/salsa-ci.yml new file mode 100644 index 000000000..ab4d9f016 --- /dev/null +++ b/debian/salsa-ci.yml @@ -0,0 +1,14 @@ +--- +include: + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/salsa-ci.yml + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/pipeline-jobs.yml + +variables: + SALSA_CI_DISABLE_APTLY: 1 + SALSA_CI_DISABLE_AUTOPKGTEST: 0 + SALSA_CI_DISABLE_BLHC: 1 + SALSA_CI_DISABLE_LINTIAN: 1 + SALSA_CI_DISABLE_PIUPARTS: 1 + SALSA_CI_DISABLE_REPROTEST: 1 + SALSA_CI_DISABLE_BUILD_PACKAGE_ALL: 1 + SALSA_CI_DISABLE_BUILD_PACKAGE_ANY: 1 diff --git a/debian/tests/control b/debian/tests/control new file mode 100644 index 000000000..a46476f58 --- /dev/null +++ b/debian/tests/control @@ -0,0 +1,2 @@ +Tests: extlinux +Depends: libguestfs-tools, mmdebstrap, linux-image-amd64, openssh-client diff --git a/debian/tests/extlinux b/debian/tests/extlinux new file mode 100644 index 000000000..e2f39ef84 --- /dev/null +++ b/debian/tests/extlinux @@ -0,0 +1,99 @@ +#!/bin/sh + +set -exu + +ssh="ssh -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -i id_rsa -T" + +pkgs="linux-image-amd64,openssh-server,systemd-sysv,libpam-systemd,policykit-1" +pkgs="$pkgs,iproute2,util-linux,e2fsprogs,ifupdown,net-tools,netbase" +pkgs="$pkgs,iputils-ping,isc-dhcp-client,lvm2,parted,cryptsetup" +pkgs="$pkgs,dropbear-initramfs,busybox,fdisk,mmdebstrap,udev" + +# we have to use root mode on salsa CI because: +# - unshare mode fails because /sys is mounted read-only +# and kernel.unprivileged_userns_clone is not set to 1 +# - fakechroot mode fails because of failing postinst of linux-image-amd64 +# - proot mode produces wrong permissions +mmdebstrap --mode=root --variant=apt --include=$pkgs \ + --customize-hook='chroot "$1" passwd --delete root' \ + --customize-hook='chroot "$1" useradd --home-dir /home/user --create-home user' \ + --customize-hook='chroot "$1" passwd --delete user' \ + --customize-hook='echo host > "$1/etc/hostname"' \ + --customize-hook='echo "127.0.0.1 localhost host" > "$1/etc/hosts"' \ + --customize-hook='echo "/dev/sda1 / auto errors=remount-ro 0 1" > "$1/etc/fstab"' \ + unstable debian-unstable.tar + +cat << END > extlinux.conf +default linux +timeout 0 + +label linux +kernel /vmlinuz +append initrd=/initrd.img root=/dev/sda1 net.ifnames=0 console=ttyS0 +END + +cat << END > interfaces +auto lo +iface lo inet loopback + +auto eth0 +iface eth0 inet dhcp +END + +[ -e ./id_rsa ] && [ -e ./id_rsa.pub ] || ssh-keygen -q -t rsa -f ./id_rsa -N "" + +#LIBGUESTFS_BACKEND_SETTINGS=force_tcg +#libguestfs-test-tool || true +#export LIBGUESTFS_DEBUG=1 LIBGUESTFS_TRACE=1 +guestfish -N debian-unstable.img=disk:1G -- \ + part-disk /dev/sda mbr : \ + part-set-bootable /dev/sda 1 true : \ + mkfs ext2 /dev/sda1 : \ + mount /dev/sda1 / : \ + tar-in debian-unstable.tar / : \ + extlinux / : \ + mkdir /root/.ssh : \ + copy-in id_rsa.pub /root/ : \ + mv /root/id_rsa.pub /root/.ssh/authorized_keys : \ + chown 0 0 /root/.ssh/authorized_keys : \ + copy-in extlinux.conf / : \ + copy-in interfaces /etc/network + +qemu-system-x86_64 -m 1G -net user,hostfwd=tcp::10022-:22,hostfwd=tcp::12222-:2222 \ + -net nic -nographic -serial mon:stdio \ + -drive file=debian-unstable.img,format=raw >qemu.log </dev/null 2>&1 & + +QEMUPID=$! + +trap "cat --show-nonprinting qemu.log; kill $QEMUPID" EXIT + +TIMESTAMP=$(sleepenh 0 || [ $? -eq 1 ]) +TIMEOUT=5 +NUM_TRIES=40 +i=0 +while true; do + rv=0 + $ssh -p 10022 -o ConnectTimeout=$TIMEOUT root@localhost echo success || rv=1 + [ $rv -eq 0 ] && break + # if the command before took less than $TIMEOUT seconds, wait the remaining time + TIMESTAMP=$(sleepenh $TIMESTAMP $TIMEOUT || [ $? -eq 1 ]); + i=$((i+1)) + if [ $i -ge $NUM_TRIES ]; then + break + fi +done + +if [ $i -eq $NUM_TRIES ]; then + echo "timeout reached: unable to connect to qemu via ssh" + exit 1 +fi + +$ssh -p 10022 root@localhost systemctl poweroff + +wait $QEMUPID + +trap - EXIT + +rm debian-unstable.img debian-unstable.tar extlinux.conf id_rsa id_rsa.pub interfaces qemu.log + +exit 0 -- 2.20.1