Package: autopkgtest Version: 5.13.1 Severity: important Tags: patch autopkgtest-virt-qemu fails to start after upgrading qemu to 5.1. This is with my 'vectis' package builder, which uses autopkgtest-virt-qemu for VMs, but the same would happen for the autopkgtest runner:
INFO:vectis.worker:Starting worker: ['autopkgtest-virt-qemu', '--overlay-dir=/var/tmp', '--ram-size=2048', '--cpus=2', '/home/smcv/.cache/vectis/amd64/debian/buster/autopkgtest.qcow2'] <VirtSubproc>: failure: ['qemu-img', 'create', '-f', 'qcow2', '-b', '/home/smcv/.cache/vectis/amd64/debian/buster/autopkgtest.qcow2', '/var/tmp/autopkgtest.qcow2.overlay-1597745276.120911'] unexpectedly produced stderr output `qemu-img: warning: Deprecated use of backing file without explicit backing format (detected format of qcow2) Patches attached. I'll send a merge request when I have a bug number. smcv
>From 4c6ac09af05cc6f9a88a034c089e2629e8936310 Mon Sep 17 00:00:00 2001 From: Simon McVittie <s...@debian.org> Date: Tue, 18 Aug 2020 11:01:42 +0100 Subject: [PATCH 1/2] qemu: Guess format of main disk image In qemu 5.1, qemu-img outputs a deprecation warning if it is made to guess the format of a disk image, on the basis that untrusted disk images can be crafted to have ambiguous contents: for example, if an image is guessed to be in raw format, a guest can overwrite suitable magic numbers to turn it into something that qemu will guess to be qcow2. autopkgtest-virt-qemu has historically accepted either raw or qcow2 images, and our images are presumably at least somewhat trusted, so explicitly guess using qemu-info to suppress the warning. A future enhancement would be to provide a way for the user to specify the format of the disk image(s) they are providing, removing the need to guess. Signed-off-by: Simon McVittie <s...@debian.org> --- virt/autopkgtest-virt-qemu | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/virt/autopkgtest-virt-qemu b/virt/autopkgtest-virt-qemu index affe094..ded7fa2 100755 --- a/virt/autopkgtest-virt-qemu +++ b/virt/autopkgtest-virt-qemu @@ -36,6 +36,7 @@ import errno import fcntl import re import argparse +import json sys.path.insert(0, '/usr/share/autopkgtest/lib') sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname( @@ -51,6 +52,7 @@ p_qemu = None ssh_port = None normal_user = None qemu_cmd_default = None +image0_format = None def parse_args(): @@ -104,15 +106,37 @@ def parse_args(): def prepare_overlay(): '''Generate a temporary overlay image''' + global image0_format + # generate a temporary overlay if args.overlay_dir: overlay = os.path.join(args.overlay_dir, os.path.basename( args.image[0]) + '.overlay-%s' % time.time()) else: overlay = os.path.join(workdir, 'overlay.img') + + # TODO: Ideally we would specify format= for these rather than + # having qemu guess... but for now, to avoid warnings from qemu-img, + # explicitly guess rather than having qemu-img do it + info = json.loads( + VirtSubproc.check_exec([ + 'qemu-img', 'info', + '--output=json', + args.image[0], + ], outp=True, timeout=5) + ) + + if 'format' not in info: + VirtSubproc.bomb('Unable to determine format of %s' % args.image[0]) + + image0_format = info['format'] + adtlog.debug('Creating temporary overlay image in %s' % overlay) - VirtSubproc.check_exec(['qemu-img', 'create', '-f', 'qcow2', '-b', - os.path.abspath(args.image[0]), overlay], + VirtSubproc.check_exec(['qemu-img', 'create', + '-f', 'qcow2', + '-F', image0_format, + '-b', os.path.abspath(args.image[0]), + overlay], outp=True, timeout=300) return overlay @@ -212,7 +236,7 @@ def setup_baseimage(): # Add the base image as an additional drive monitor = VirtSubproc.get_unix_socket(os.path.join(workdir, 'monitor')) - monitor.sendall(('drive_add 0 file=%s,if=none,readonly=on,serial=BASEIMAGE,id=drive-baseimage\n' % args.image[0]).encode()) + monitor.sendall(('drive_add 0 file=%s,if=none,readonly=on,serial=BASEIMAGE,id=drive-baseimage,format=%s\n' % (args.image[0], image0_format)).encode()) VirtSubproc.expect(monitor, b'(qemu)', 10) monitor.sendall(b'device_add virtio-blk-pci,drive=drive-baseimage,id=virtio-baseimage\n') VirtSubproc.expect(monitor, b'(qemu)', 10) @@ -557,7 +581,7 @@ def hook_open(): '-serial', 'unix:%s/ttyS1,server,nowait' % workdir, '-virtfs', 'local,id=autopkgtest,path=%s,security_model=none,mount_tag=autopkgtest' % shareddir, - '-drive', 'file=%s,cache=unsafe,if=virtio,index=0' % overlay] + '-drive', 'file=%s,cache=unsafe,if=virtio,index=0,format=qcow2' % overlay] if args.efi: code = None @@ -583,6 +607,8 @@ def hook_open(): argv.append('if=pflash,format=raw,file=%s/efivars.fd' % workdir) for i, image in enumerate(args.image[1:]): + # TODO: Ideally we would specify format= for these rather than + # having qemu guess argv.append('-drive') argv.append('file=%s,if=virtio,index=%i,readonly' % (image, i + 1)) -- 2.28.0
>From a3f70d4675359767e8f138a2ecfc6d540b29d78b Mon Sep 17 00:00:00 2001 From: Simon McVittie <s...@debian.org> Date: Tue, 18 Aug 2020 11:07:31 +0100 Subject: [PATCH 2/2] tools: Don't make qemu guess what format the disk image is In autopkgtest-build-qemu, we know vmdb2 produced a raw image; in autopkgtest-buildvm-ubuntu-cloud, we know that the Ubuntu image is in qcow2 format, while the cloud-init seed generated by genisoimage is a raw image. Signed-off-by: Simon McVittie <s...@debian.org> --- tools/autopkgtest-build-qemu | 2 +- tools/autopkgtest-buildvm-ubuntu-cloud | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/autopkgtest-build-qemu b/tools/autopkgtest-build-qemu index 9760da1..3d6666a 100755 --- a/tools/autopkgtest-build-qemu +++ b/tools/autopkgtest-build-qemu @@ -310,7 +310,7 @@ vmdb2 \ --image="$image".raw \ "$vmdb2_config" -qemu-img convert -O qcow2 "$image".raw "$image".new +qemu-img convert -f raw -O qcow2 "$image".raw "$image".new rm -f "$image".raw diff --git a/tools/autopkgtest-buildvm-ubuntu-cloud b/tools/autopkgtest-buildvm-ubuntu-cloud index 5b61d86..d396f91 100755 --- a/tools/autopkgtest-buildvm-ubuntu-cloud +++ b/tools/autopkgtest-buildvm-ubuntu-cloud @@ -202,7 +202,7 @@ def download_image(cloud_img_url, release, arch): def resize_image(image, size): print('Resizing image, adding %s...' % size) - subprocess.check_call(['qemu-img', 'resize', image, '+' + size]) + subprocess.check_call(['qemu-img', 'resize', '-f', 'qcow2', image, '+' + size]) DEFAULT_METADATA = 'instance-id: nocloud\nlocal-hostname: autopkgtest\n' @@ -339,8 +339,8 @@ def boot_image(image, seed, qemu_command, verbose, timeout): '-net', 'user', '-net', 'nic,model=virtio', '-serial', 'unix:%s,server,nowait' % tty_sock, - '-drive', 'file=%s,if=virtio' % image, - '-drive', 'file=%s,if=virtio,readonly' % seed] + '-drive', 'file=%s,if=virtio,format=qcow2' % image, + '-drive', 'file=%s,if=virtio,format=raw,readonly' % seed] if os.path.exists('/dev/kvm'): argv.append('-enable-kvm') -- 2.28.0