Bug#800845: autopkgtest: Add support for nested VMs

Christian Seiler christian at iwakd.de
Sun Oct 4 11:51:45 UTC 2015

Package: autopkgtest
Version: 3.17.2
Severity: wishlist
Tags: patch

Hello Martin,

as per our discussion on the autopkgtest mailing list [1], I'd like to
be able to have autopkgtest support nested VMs for testing of network
clients in the kernel such as NFS, CIFS, iSCSI, NBD, etc.

The logic would be to

 - have the test environment run a simple server that the client may
   connect to
 - have a copy of the qcow2 base image in the test environment
 - create a QEMU/KVM VM in the test environment that then tests the
   client (this can again be done with adt-run inside the test env)

I've attached two patches that implement the necessary changes to
autopkgtest. They are quire minimal in fact:

 1. Have adt-virt-qemu add an additional drive to the VM that
    maps (read-only) to the qcow2 base image (but without QEMU
    interpreting the image, just passing it through via format=raw).

    This allows the drive to be used as a base image, e.g.
    qemu-img create -f qcow2 -b /dev/vdb overlay.img
    (Running KVM on top of something like that works, btw., in case
    you were wondering - you can easily try that by creating a loop
    device, i.e. losetup --show -f base.img and then doing
    adt-run ... --- adt-virt-qemu /dev/loopX.)

 2. Have adt-virt-qemu provide an environment variable to the tests
    so that they may make use of it. (ADT_QCOW2_BASEIMAGE)

 3. Have adt-virt-qemu export the capability provides-qcow2-baseimage.

 4. Add new restriction needs-qcow2-baseimage that is checked against
    that capability. (The base image logic is done unconditionally by
    adt-virt-qemu, regardless of the restriction. In principle this
    would allow people to just do vmdebootstrap inside the VM if the
    base image were not to be exported.)

 5. If in KVM mode, add -cpu host option to the emulator command, since
    that is required (but not sufficient) for nested KVM to work.

    Note that nested KVM will also require a module option to be set.
    (nested=1 for either the kvm_intel or kvm_amd module.) Setting
    -cpu host has no negative side effects even if nested=0 is set on
    the host - then the kvm_* modules will not load in the VM and KVM
    will simply be not available - same as without -cpu host.

    On the other hand, nested KVM is nice-to-have, but not required for
    a nested VM - the VM inside could be a non-accelerated QEMU VM.

Once could in principle also add support for nested KVM to adt-virt-lxc
by simply allowing the administrator to specify an additional qcow2
base image on the command line. That could be done in an additional

I've updated the documentation to reflect the base image changes.

It would be great if that could be added to autopkgtest.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-needs-qcow2-baseimage-restriction.patch
Type: text/x-diff
Size: 7337 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/autopkgtest-devel/attachments/20151004/c7d0e812/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-adt-virt-qemu-emulate-host-type-CPU.patch
Type: text/x-diff
Size: 1178 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/autopkgtest-devel/attachments/20151004/c7d0e812/attachment-0001.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: OpenPGP digital signature
URL: <http://lists.alioth.debian.org/pipermail/autopkgtest-devel/attachments/20151004/c7d0e812/attachment.sig>

More information about the autopkgtest-devel mailing list